mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Generalize Wolf to Tameable
Also generalize Arrow to Projectile For MCCORE-263
This commit is contained in:
parent
79e93edfef
commit
3f211c6277
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wolf;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -105,12 +104,15 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
EntityType type = entity.getType();
|
|
||||||
DamageCause cause = event.getCause();
|
DamageCause cause = event.getCause();
|
||||||
|
|
||||||
switch(type) {
|
if (!(entity instanceof LivingEntity)) {
|
||||||
case PLAYER:
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LivingEntity lEntity = (LivingEntity) entity;
|
||||||
|
|
||||||
|
if (lEntity instanceof Player) {
|
||||||
/* Check for invincibility */
|
/* Check for invincibility */
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
PlayerProfile PP = Users.getProfile(player);
|
PlayerProfile PP = Users.getProfile(player);
|
||||||
@ -132,18 +134,12 @@ public class EntityListener implements Listener {
|
|||||||
PP.setRecentlyHurt(System.currentTimeMillis());
|
PP.setRecentlyHurt(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
} else if (lEntity instanceof Tameable) {
|
||||||
|
Tameable pet = (Tameable) lEntity;
|
||||||
|
|
||||||
case WOLF:
|
if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (pet.getOwner() instanceof Player)) {
|
||||||
Wolf wolf = (Wolf) entity;
|
|
||||||
|
|
||||||
if ((!Misc.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) {
|
|
||||||
Taming.preventDamage(event);
|
Taming.preventDamage(event);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import org.bukkit.entity.AnimalTamer;
|
|||||||
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;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
@ -51,11 +51,11 @@ public class Axes {
|
|||||||
public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
|
public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof Wolf) {
|
if (entity instanceof Tameable) {
|
||||||
Wolf wolf = (Wolf) entity;
|
Tameable pet = (Tameable) entity;
|
||||||
|
|
||||||
if (wolf.isTamed()) {
|
if (pet.isTamed()) {
|
||||||
AnimalTamer tamer = wolf.getOwner();
|
AnimalTamer tamer = pet.getOwner();
|
||||||
|
|
||||||
if (tamer instanceof Player) {
|
if (tamer instanceof Player) {
|
||||||
Player owner = (Player) tamer;
|
Player owner = (Player) tamer;
|
||||||
|
@ -6,6 +6,7 @@ import org.bukkit.entity.AnimalTamer;
|
|||||||
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;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
@ -34,11 +35,11 @@ public class Swords {
|
|||||||
*/
|
*/
|
||||||
public static void bleedCheck(Player attacker, LivingEntity entity, mcMMO plugin) {
|
public static void bleedCheck(Player attacker, LivingEntity entity, mcMMO plugin) {
|
||||||
|
|
||||||
if (entity instanceof Wolf) {
|
if (entity instanceof Tameable) {
|
||||||
Wolf wolf = (Wolf) entity;
|
Tameable pet = (Tameable) entity;
|
||||||
|
|
||||||
if (wolf.isTamed()) {
|
if (pet.isTamed()) {
|
||||||
AnimalTamer tamer = wolf.getOwner();
|
AnimalTamer tamer = pet.getOwner();
|
||||||
|
|
||||||
if (tamer instanceof Player) {
|
if (tamer instanceof Player) {
|
||||||
Player owner = (Player) tamer;
|
Player owner = (Player) tamer;
|
||||||
|
@ -132,6 +132,10 @@ public class Taming {
|
|||||||
final int THICK_FUR_MODIFIER = 2;
|
final int THICK_FUR_MODIFIER = 2;
|
||||||
final int SHOCK_PROOF_MODIFIER = 6;
|
final int SHOCK_PROOF_MODIFIER = 6;
|
||||||
|
|
||||||
|
if (!(event.getEntity() instanceof Wolf)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DamageCause cause = event.getCause();
|
DamageCause cause = event.getCause();
|
||||||
Wolf wolf = (Wolf) event.getEntity();
|
Wolf wolf = (Wolf) event.getEntity();
|
||||||
Player master = (Player) wolf.getOwner();
|
Player master = (Player) wolf.getOwner();
|
||||||
|
@ -3,12 +3,13 @@ package com.gmail.nossr50.util;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.entity.Animals;
|
||||||
import org.bukkit.entity.Arrow;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.IronGolem;
|
import org.bukkit.entity.IronGolem;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
@ -51,11 +52,11 @@ public class Combat {
|
|||||||
|
|
||||||
Entity damager = event.getDamager();
|
Entity damager = event.getDamager();
|
||||||
LivingEntity target = (LivingEntity) event.getEntity();
|
LivingEntity target = (LivingEntity) event.getEntity();
|
||||||
EntityType damagerType = damager.getType();
|
|
||||||
EntityType targetType = target.getType();
|
|
||||||
|
|
||||||
switch (damagerType) {
|
boolean targetIsPlayer = target instanceof Player;
|
||||||
case PLAYER:
|
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
||||||
|
|
||||||
|
if (damager instanceof Player) {
|
||||||
Player attacker = (Player) event.getDamager();
|
Player attacker = (Player) event.getDamager();
|
||||||
ItemStack itemInHand = attacker.getItemInHand();
|
ItemStack itemInHand = attacker.getItemInHand();
|
||||||
PlayerProfile PPa = Users.getProfile(attacker);
|
PlayerProfile PPa = Users.getProfile(attacker);
|
||||||
@ -64,13 +65,13 @@ public class Combat {
|
|||||||
|
|
||||||
if (ItemChecks.isSword(itemInHand) && permInstance.swords(attacker)) {
|
if (ItemChecks.isSword(itemInHand) && permInstance.swords(attacker)) {
|
||||||
if (!configInstance.getSwordsPVP()) {
|
if (!configInstance.getSwordsPVP()) {
|
||||||
if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (targetIsPlayer || targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configInstance.getSwordsPVE()) {
|
if (!configInstance.getSwordsPVE()) {
|
||||||
if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (!targetIsPlayer || !targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,13 +89,13 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
else if (ItemChecks.isAxe(itemInHand) && permInstance.axes(attacker)) {
|
else if (ItemChecks.isAxe(itemInHand) && permInstance.axes(attacker)) {
|
||||||
if (!configInstance.getAxesPVP()) {
|
if (!configInstance.getAxesPVP()) {
|
||||||
if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (targetIsPlayer || targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configInstance.getAxesPVE()) {
|
if (!configInstance.getAxesPVE()) {
|
||||||
if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (!targetIsPlayer || !targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,13 +120,13 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
else if (itemInHand.getType().equals(Material.AIR) && permInstance.unarmed(attacker)) {
|
else if (itemInHand.getType().equals(Material.AIR) && permInstance.unarmed(attacker)) {
|
||||||
if (!configInstance.getUnarmedPVP()) {
|
if (!configInstance.getUnarmedPVP()) {
|
||||||
if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (targetIsPlayer || targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configInstance.getUnarmedPVE()) {
|
if (!configInstance.getUnarmedPVE()) {
|
||||||
if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (!targetIsPlayer || !targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +139,7 @@ public class Combat {
|
|||||||
event.setDamage((int) (event.getDamage() * 1.5));
|
event.setDamage((int) (event.getDamage() * 1.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetType.equals(EntityType.PLAYER) && permInstance.disarm(attacker)) {
|
if (targetIsPlayer && permInstance.disarm(attacker)) {
|
||||||
Unarmed.disarmProcCheck(attacker, (Player) target);
|
Unarmed.disarmProcCheck(attacker, (Player) target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,9 +148,7 @@ public class Combat {
|
|||||||
else if (itemInHand.getType().equals(Material.BONE) && permInstance.beastLore(attacker)) {
|
else if (itemInHand.getType().equals(Material.BONE) && permInstance.beastLore(attacker)) {
|
||||||
Taming.beastLore(event, target, attacker);
|
Taming.beastLore(event, target, attacker);
|
||||||
}
|
}
|
||||||
break;
|
} else if (damager instanceof Tameable) {
|
||||||
|
|
||||||
case WOLF:
|
|
||||||
Wolf wolf = (Wolf) damager;
|
Wolf wolf = (Wolf) damager;
|
||||||
|
|
||||||
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
||||||
@ -157,13 +156,13 @@ public class Combat {
|
|||||||
PlayerProfile PPo = Users.getProfile(master);
|
PlayerProfile PPo = Users.getProfile(master);
|
||||||
|
|
||||||
if (!configInstance.getTamingPVP()) {
|
if (!configInstance.getTamingPVP()) {
|
||||||
if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (targetIsPlayer || targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configInstance.getTamingPVE()) {
|
if (!configInstance.getTamingPVE()) {
|
||||||
if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (!targetIsPlayer || !targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,39 +183,36 @@ public class Combat {
|
|||||||
startGainXp(master, PPo, target, SkillType.TAMING, plugin);
|
startGainXp(master, PPo, target, SkillType.TAMING, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
} else if (damager instanceof Projectile) {
|
||||||
|
if (!configInstance.getArcheryPVP() && ((Projectile) damager).getShooter().getType().equals(EntityType.PLAYER)) {
|
||||||
case ARROW:
|
if (targetIsPlayer || targetIsTamedPet) {
|
||||||
if (!configInstance.getArcheryPVP() && ((Arrow) damager).getShooter().getType().equals(EntityType.PLAYER)) {
|
|
||||||
if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configInstance.getArcheryPVE() && !((Arrow) damager).getShooter().getType().equals(EntityType.PLAYER)) {
|
if (!configInstance.getArcheryPVE() && !((Projectile) damager).getShooter().getType().equals(EntityType.PLAYER)) {
|
||||||
if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) {
|
if (!targetIsPlayer || !targetIsTamedPet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
archeryCheck(event, plugin);
|
archeryCheck(event, plugin);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetType.equals(EntityType.PLAYER)) {
|
if (target instanceof Player) {
|
||||||
if (configInstance.getSwordsPVP() && damagerType.equals(EntityType.PLAYER)) {
|
if (configInstance.getSwordsPVP() && damager instanceof Player) {
|
||||||
Swords.counterAttackChecks(event);
|
Swords.counterAttackChecks(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getSwordsPVE() && !damagerType.equals(EntityType.PLAYER)) {
|
if (configInstance.getSwordsPVE() && !(damager instanceof Player)) {
|
||||||
Swords.counterAttackChecks(event);
|
Swords.counterAttackChecks(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getAcrobaticsPVP() && damagerType.equals(EntityType.PLAYER)) {
|
if (configInstance.getAcrobaticsPVP() && damager instanceof Player) {
|
||||||
Acrobatics.dodgeChecks(event);
|
Acrobatics.dodgeChecks(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getAcrobaticsPVE() && !damagerType.equals(EntityType.PLAYER)) {
|
if (configInstance.getAcrobaticsPVE() && !(damager instanceof Player)) {
|
||||||
Acrobatics.dodgeChecks(event);
|
Acrobatics.dodgeChecks(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,7 +244,7 @@ public class Combat {
|
|||||||
* @param pluginx mcMMO plugin instance
|
* @param pluginx mcMMO plugin instance
|
||||||
*/
|
*/
|
||||||
public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) {
|
public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) {
|
||||||
Arrow arrow = (Arrow) event.getDamager();
|
Projectile arrow = (Projectile) event.getDamager();
|
||||||
LivingEntity shooter = arrow.getShooter();
|
LivingEntity shooter = arrow.getShooter();
|
||||||
LivingEntity target = (LivingEntity) event.getEntity();
|
LivingEntity target = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
@ -388,19 +384,7 @@ public class Combat {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (entity.getType()) {
|
if (entity instanceof Player) {
|
||||||
case WOLF:
|
|
||||||
AnimalTamer tamer = ((Wolf) entity).getOwner();
|
|
||||||
|
|
||||||
if (tamer instanceof Player) {
|
|
||||||
if (tamer.equals(attacker) || Party.getInstance().inSameParty(attacker, (Player) tamer)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLAYER:
|
|
||||||
Player defender = (Player) entity;
|
Player defender = (Player) entity;
|
||||||
|
|
||||||
if (!target.getWorld().getPVP()) {
|
if (!target.getWorld().getPVP()) {
|
||||||
@ -420,11 +404,14 @@ public class Combat {
|
|||||||
if (playerProfile.getGodMode()) {
|
if (playerProfile.getGodMode()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if (entity instanceof Tameable) {
|
||||||
|
AnimalTamer tamer = ((Tameable) entity).getOwner();
|
||||||
|
|
||||||
break;
|
if (tamer instanceof Player) {
|
||||||
|
if (tamer.equals(attacker) || Party.getInstance().inSameParty(attacker, (Player) tamer)) {
|
||||||
default:
|
continue;
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user