Browse Source

Wolfs no longer kill themselves + tamed mob heart death message bug

nossr50 6 years ago
parent
commit
34869914c4

+ 6 - 0
Changelog.txt

@@ -1,3 +1,9 @@
+Version 2.1.60
+    Fixed a NPE error if a LivingEntity's target was set to null
+    Fixed a bug where tamed mobs could kill themselves if their owner shot them once
+    Corrected a typo when naming entities summoned by COTW (Locale string - Taming.Summon.Name.Format)
+    Fixed a bug where tamed mobs could have hearts instead of their name in their own death messages
+
 Version 2.1.59
     Raised the overfishing limit from 3 to 10
     Improved the overfishing messages to be more clear about its mechanics

+ 2 - 2
pom.xml

@@ -2,7 +2,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.gmail.nossr50.mcMMO</groupId>
     <artifactId>mcMMO</artifactId>
-    <version>2.1.59</version>
+    <version>2.1.60-SNAPSHOT</version>
     <name>mcMMO</name>
     <url>https://github.com/mcMMO-Dev/mcMMO</url>
     <scm>
@@ -167,7 +167,7 @@
         <dependency>
             <groupId>org.spigotmc</groupId>
             <artifactId>spigot-api</artifactId>
-            <version>1.14-R0.1-SNAPSHOT</version>
+            <version>1.14.1-R0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

+ 7 - 7
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -66,16 +66,16 @@ public class BlockListener implements Listener {
                 continue;
 
             //TODO: Should just store the amount of drops in the metadata itself and use a loop
-            if(event.getBlock().getState().getMetadata(mcMMO.doubleDrops).size() > 0)
+            if(event.getBlock().getMetadata(mcMMO.doubleDrops).size() > 0)
             {
-                event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
-                event.getBlock().getState().removeMetadata(mcMMO.doubleDrops, plugin);
+                event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
+                event.getBlock().removeMetadata(mcMMO.doubleDrops, plugin);
             }
-            else if(event.getBlock().getState().getMetadata(mcMMO.tripleDrops).size() > 0)
+            else if(event.getBlock().getMetadata(mcMMO.tripleDrops).size() > 0)
             {
-                event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
-                event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
-                event.getBlock().getState().removeMetadata(mcMMO.tripleDrops, plugin);
+                event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
+                event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
+                event.getBlock().removeMetadata(mcMMO.tripleDrops, plugin);
             }
         }
     }

+ 12 - 14
src/main/java/com/gmail/nossr50/listeners/EntityListener.java

@@ -25,6 +25,7 @@ import com.gmail.nossr50.util.player.UserManager;
 import com.gmail.nossr50.util.skills.CombatUtils;
 import com.gmail.nossr50.worldguard.WorldGuardManager;
 import com.gmail.nossr50.worldguard.WorldGuardUtils;
+import org.bukkit.Bukkit;
 import org.bukkit.Material;
 import org.bukkit.OfflinePlayer;
 import org.bukkit.block.Block;
@@ -72,6 +73,12 @@ public class EntityListener implements Listener {
         if(!ExperienceConfig.getInstance().isEndermanEndermiteFarmingPrevented())
             return;
 
+        //It's rare but targets can be null sometimes
+        if(event.getTarget() == null)
+        {
+            return;
+        }
+
         //Prevent entities from giving XP if they target endermite
         if(event.getTarget() instanceof Endermite)
         {
@@ -386,24 +393,15 @@ public class EntityListener implements Listener {
         /**
          * This sets entity names back to whatever they are supposed to be
          */
-        if(!(attacker instanceof Player) && defender instanceof Player)
+        if(event.getFinalDamage() >= target.getHealth())
         {
-            if(event.getFinalDamage() >= ((LivingEntity) defender).getHealth())
+            if(attacker instanceof LivingEntity)
             {
-                List<MetadataValue> metadataValue = attacker.getMetadata("mcMMO_oldName");
-
-                if(metadataValue.size() <= 0)
-                    return;
-
-                if(metadataValue != null)
-                {
-                    OldName oldName = (OldName) metadataValue.get(0);
-                    attacker.setCustomName(oldName.asString());
-                    attacker.setCustomNameVisible(false);
-                }
+                CombatUtils.fixNames(event, (LivingEntity) attacker);
             }
-        }
 
+            CombatUtils.fixNames(event, target);
+        }
 
     }
 

+ 22 - 14
src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java

@@ -231,6 +231,14 @@ public class TamingManager extends SkillManager {
     }
 
     public void attackTarget(LivingEntity target) {
+        if(target instanceof Tameable)
+        {
+            Tameable tameable = (Tameable) target;
+            if(tameable.getOwner() == getPlayer())
+            {
+                return;
+            }
+        }
         double range = 5;
         Player player = getPlayer();
 
@@ -281,36 +289,36 @@ public class TamingManager extends SkillManager {
             }
 
             location = Misc.getLocationOffset(location, 1);
-            LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type);
+            LivingEntity callOfWildEntity = (LivingEntity) player.getWorld().spawnEntity(location, type);
 
-            FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player);
+            FakeEntityTameEvent event = new FakeEntityTameEvent(callOfWildEntity, player);
             mcMMO.p.getServer().getPluginManager().callEvent(event);
 
             if (event.isCancelled()) {
                 continue;
             }
 
-            entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
-            ((Tameable) entity).setOwner(player);
-            entity.setRemoveWhenFarAway(false);
+            callOfWildEntity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
+            ((Tameable) callOfWildEntity).setOwner(player);
+            callOfWildEntity.setRemoveWhenFarAway(false);
 
-            addToTracker(entity);
+            addToTracker(callOfWildEntity);
 
             switch (type) {
                 case OCELOT:
-                    ((Ocelot) entity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]);
+                    ((Ocelot) callOfWildEntity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]);
                     break;
 
                 case WOLF:
-                    entity.setMaxHealth(20.0);
-                    entity.setHealth(entity.getMaxHealth());
+                    callOfWildEntity.setMaxHealth(20.0);
+                    callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth());
                     break;
 
                 case HORSE:
-                    Horse horse = (Horse) entity;
+                    Horse horse = (Horse) callOfWildEntity;
 
-                    entity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15));
-                    entity.setHealth(entity.getMaxHealth());
+                    callOfWildEntity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15));
+                    callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth());
                     horse.setColor(Horse.Color.values()[Misc.getRandom().nextInt(Horse.Color.values().length)]);
                     horse.setStyle(Horse.Style.values()[Misc.getRandom().nextInt(Horse.Style.values().length)]);
                     horse.setJumpStrength(Math.max(AdvancedConfig.getInstance().getMinHorseJumpStrength(), Math.min(Math.min(Misc.getRandom().nextDouble(), Misc.getRandom().nextDouble()) * 2, AdvancedConfig.getInstance().getMaxHorseJumpStrength())));
@@ -322,10 +330,10 @@ public class TamingManager extends SkillManager {
             }
 
             if (Permissions.renamePets(player)) {
-                entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
+                callOfWildEntity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
             }
 
-            ParticleEffectUtils.playCallOfTheWildEffect(entity);
+            ParticleEffectUtils.playCallOfTheWildEffect(callOfWildEntity);
         }
 
         ItemStack leftovers = new ItemStack(heldItem);

+ 23 - 0
src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java

@@ -3,6 +3,7 @@ package com.gmail.nossr50.util.skills;
 import com.gmail.nossr50.config.experience.ExperienceConfig;
 import com.gmail.nossr50.datatypes.experience.XPGainReason;
 import com.gmail.nossr50.datatypes.interactions.NotificationType;
+import com.gmail.nossr50.datatypes.meta.OldName;
 import com.gmail.nossr50.datatypes.player.McMMOPlayer;
 import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 import com.gmail.nossr50.datatypes.skills.SubSkillType;
@@ -30,10 +31,12 @@ import org.bukkit.event.entity.EntityDamageEvent;
 import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
 import org.bukkit.inventory.ItemStack;
+import org.bukkit.metadata.MetadataValue;
 import org.bukkit.projectiles.ProjectileSource;
 
 import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 public final class CombatUtils {
@@ -358,6 +361,26 @@ public final class CombatUtils {
         }
     }
 
+    /**
+     * This cleans up names from displaying in chat as hearts
+     * @param event target event
+     * @param entity target entity
+     */
+    public static void fixNames(EntityDamageByEntityEvent event, LivingEntity entity)
+    {
+        List<MetadataValue> metadataValue = entity.getMetadata("mcMMO_oldName");
+
+        if(metadataValue.size() <= 0)
+            return;
+
+        if(metadataValue != null)
+        {
+            OldName oldName = (OldName) metadataValue.get(0);
+            entity.setCustomName(oldName.asString());
+            entity.setCustomNameVisible(false);
+        }
+    }
+
     public static int getLimitBreakDamage(Player player, SubSkillType subSkillType) {
         return RankUtils.getRank(player, subSkillType);
     }

+ 1 - 1
src/main/resources/locale/locale_en_US.properties

@@ -478,7 +478,7 @@ Taming.Summon.Fail.Ocelot=[[RED]]You have too many ocelots nearby to summon any
 Taming.Summon.Fail.Wolf=[[RED]]You have too many wolves nearby to summon any more.
 Taming.Summon.Fail.Horse=[[RED]]You have too many horses nearby to summon any more.
 Taming.Summon.Fail.TooMany=[[RED]]You have reached the maximum limit of pets to summon. [[YELLOW]]({0})
-Taming.Summon.Name.Format={0}''s {1}
+Taming.Summon.Name.Format={0}'s {1}
 #UNARMED
 Unarmed.Ability.Bonus.0=Iron Arm Style
 Unarmed.Ability.Bonus.1=+{0} DMG Upgrade