mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-03 18:43:43 +01:00 
			
		
		
		
	Add lifespan to Taming summons
This commit is contained in:
		@@ -27,6 +27,8 @@ Version 1.5.01-dev
 | 
			
		||||
 + Added options to tools.yml and armor.yml config files to set a pretty repair material name
 | 
			
		||||
 + Added full support for repairables in tools.yml and armor.yml config files
 | 
			
		||||
 + Added magical mod config file import command, for Cauldron 1.7+. Check wiki for usage
 | 
			
		||||
 + Added particle effects and sounds to "Call of the Wild" (Taming)
 | 
			
		||||
 + Added summon length to "Call of the Wild". Summons will now commit suicide after their lifespan expires
 | 
			
		||||
 = Fixed bug where pistons would mess with the block tracking
 | 
			
		||||
 = Fixed bug where the Updater was running on the main thread.
 | 
			
		||||
 = Fixed bug when players would use /ptp without being in a party
 | 
			
		||||
 
 | 
			
		||||
@@ -383,6 +383,7 @@ public class Config extends AutoUpdateConfigLoader {
 | 
			
		||||
    public boolean getDodgeEffectEnabled() { return config.getBoolean("Particles.Dodge", true); }
 | 
			
		||||
    public boolean getBleedEffectEnabled() { return config.getBoolean("Particles.Bleed", true); }
 | 
			
		||||
    public boolean getGreaterImpactEffectEnabled() { return config.getBoolean("Particles.Greater_Impact", true); }
 | 
			
		||||
    public boolean getCallOfTheWildEffectEnabled() { return config.getBoolean("Particles.Call_of_the_Wild", true); }
 | 
			
		||||
    public boolean getLevelUpEffectsEnabled() { return config.getBoolean("Particles.LevelUp_Enabled", true); }
 | 
			
		||||
    public int getLevelUpEffectsTier() { return config.getInt("Particles.LevelUp_Tier", 100); }
 | 
			
		||||
    public boolean getLargeFireworks() { return config.getBoolean("Particles.LargeFireworks", true); }
 | 
			
		||||
@@ -496,7 +497,9 @@ public class Config extends AutoUpdateConfigLoader {
 | 
			
		||||
    public Material getTamingCOTWMaterial(EntityType type) { return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Material")); }
 | 
			
		||||
    public int getTamingCOTWCost(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Amount"); }
 | 
			
		||||
    public int getTamingCOTWAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Amount"); }
 | 
			
		||||
    public int getTamingCOTWLength(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ ".Summon_Length"); }
 | 
			
		||||
    public double getTamingCOTWRange() { return config.getDouble("Skills.Taming.Call_Of_The_Wild.Range", 40.0D); }
 | 
			
		||||
    public int getTamingCOTWMaxAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ "_MaxAmount"); }
 | 
			
		||||
 | 
			
		||||
    /* Woodcutting */
 | 
			
		||||
    public boolean getWoodcuttingDoubleDropsEnabled(TreeSpecies species) { return config.getBoolean("Double_Drops.Woodcutting." + StringUtils.getPrettyTreeSpeciesString(species).replace(" ", "_")); }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,12 @@
 | 
			
		||||
package com.gmail.nossr50.skills.taming;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.EntityEffect;
 | 
			
		||||
import org.bukkit.entity.AnimalTamer;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.entity.Tameable;
 | 
			
		||||
import org.bukkit.entity.Wolf;
 | 
			
		||||
@@ -12,6 +16,8 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
 | 
			
		||||
import com.gmail.nossr50.locale.LocaleLoader;
 | 
			
		||||
 | 
			
		||||
public class Taming {
 | 
			
		||||
    private static List<TrackedTamingEntity> trackedEntities = new ArrayList<TrackedTamingEntity>();
 | 
			
		||||
 | 
			
		||||
    public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock();
 | 
			
		||||
    public static int holyHoundUnlockLevel            = AdvancedConfig.getInstance().getHolyHoundUnlock();
 | 
			
		||||
 | 
			
		||||
@@ -75,4 +81,14 @@ public class Taming {
 | 
			
		||||
                return "";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static void addToTracker(LivingEntity livingEntity) {
 | 
			
		||||
        TrackedTamingEntity trackedEntity = new TrackedTamingEntity(livingEntity);
 | 
			
		||||
 | 
			
		||||
        trackedEntities.add(trackedEntity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static void removeFromTracker(TrackedTamingEntity trackedEntity) {
 | 
			
		||||
        trackedEntities.remove(trackedEntity);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package com.gmail.nossr50.skills.taming;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Sound;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.Horse;
 | 
			
		||||
@@ -24,6 +26,7 @@ import com.gmail.nossr50.skills.SkillManager;
 | 
			
		||||
import com.gmail.nossr50.util.Misc;
 | 
			
		||||
import com.gmail.nossr50.util.Permissions;
 | 
			
		||||
import com.gmail.nossr50.util.StringUtils;
 | 
			
		||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
 | 
			
		||||
import com.gmail.nossr50.util.skills.SkillUtils;
 | 
			
		||||
 | 
			
		||||
public class TamingManager extends SkillManager {
 | 
			
		||||
@@ -208,6 +211,7 @@ public class TamingManager extends SkillManager {
 | 
			
		||||
 | 
			
		||||
        ItemStack heldItem = player.getItemInHand();
 | 
			
		||||
        int heldItemAmount = heldItem.getAmount();
 | 
			
		||||
        Location location = player.getLocation();
 | 
			
		||||
 | 
			
		||||
        if (heldItemAmount < summonAmount) {
 | 
			
		||||
            player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(heldItem.getType())));
 | 
			
		||||
@@ -219,9 +223,10 @@ public class TamingManager extends SkillManager {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int amount = Config.getInstance().getTamingCOTWAmount(type);
 | 
			
		||||
        int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(type);
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < amount; i++) {
 | 
			
		||||
            LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
 | 
			
		||||
            LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type);
 | 
			
		||||
 | 
			
		||||
            FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player);
 | 
			
		||||
            mcMMO.p.getServer().getPluginManager().callEvent(event);
 | 
			
		||||
@@ -234,6 +239,10 @@ public class TamingManager extends SkillManager {
 | 
			
		||||
            ((Tameable) entity).setOwner(player);
 | 
			
		||||
            entity.setRemoveWhenFarAway(false);
 | 
			
		||||
 | 
			
		||||
            if (tamingCOTWLength > 0) {
 | 
			
		||||
                Taming.addToTracker(entity);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            switch (type) {
 | 
			
		||||
                case OCELOT:
 | 
			
		||||
                    ((Ocelot) entity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]);
 | 
			
		||||
@@ -263,10 +272,19 @@ public class TamingManager extends SkillManager {
 | 
			
		||||
                entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
 | 
			
		||||
                entity.setCustomNameVisible(true);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ParticleEffectUtils.playCallOfTheWildEffect(entity);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player.setItemInHand(heldItemAmount == summonAmount ? null : new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
 | 
			
		||||
        player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
 | 
			
		||||
 | 
			
		||||
        String lifeSpan = "";
 | 
			
		||||
        if (tamingCOTWLength > 0) {
 | 
			
		||||
            lifeSpan = LocaleLoader.getString("Taming.Summon.Lifespan", tamingCOTWLength);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete") + lifeSpan);
 | 
			
		||||
        player.playSound(location, Sound.FIREWORK_LARGE_BLAST2, 1F, 0.5F);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean rangeCheck(EntityType type) {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,57 @@
 | 
			
		||||
package com.gmail.nossr50.skills.taming;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Sound;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
import com.gmail.nossr50.mcMMO;
 | 
			
		||||
import com.gmail.nossr50.config.Config;
 | 
			
		||||
import com.gmail.nossr50.util.Misc;
 | 
			
		||||
import com.gmail.nossr50.util.skills.CombatUtils;
 | 
			
		||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
 | 
			
		||||
 | 
			
		||||
public class TrackedTamingEntity extends BukkitRunnable {
 | 
			
		||||
    private LivingEntity livingEntity;
 | 
			
		||||
    private UUID id;
 | 
			
		||||
    private long timeStamp;
 | 
			
		||||
    private int length;
 | 
			
		||||
 | 
			
		||||
    protected TrackedTamingEntity(LivingEntity livingEntity) {
 | 
			
		||||
        this.livingEntity = livingEntity;
 | 
			
		||||
        this.id = livingEntity.getUniqueId();
 | 
			
		||||
        this.timeStamp = System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR;
 | 
			
		||||
 | 
			
		||||
        this.length = Config.getInstance().getTamingCOTWLength(livingEntity.getType()) * Misc.TICK_CONVERSION_FACTOR;
 | 
			
		||||
 | 
			
		||||
        this.runTaskLater(mcMMO.p, length);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void run() {
 | 
			
		||||
        if (livingEntity.isValid()) {
 | 
			
		||||
            Location location = livingEntity.getLocation();
 | 
			
		||||
            location.getWorld().playSound(location, Sound.FIZZ, 0.8F, 0.8F);
 | 
			
		||||
            ParticleEffectUtils.playCallOfTheWildEffect(livingEntity);
 | 
			
		||||
            CombatUtils.dealDamage(livingEntity, livingEntity.getMaxHealth(), DamageCause.SUICIDE, livingEntity);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Taming.removeFromTracker(this);
 | 
			
		||||
        this.cancel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected LivingEntity getLivingEntity() {
 | 
			
		||||
        return livingEntity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected UUID getID() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected long getTimeStamp() {
 | 
			
		||||
        return timeStamp;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -59,6 +59,14 @@ public final class ParticleEffectUtils {
 | 
			
		||||
        livingEntity.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void playCallOfTheWildEffect(LivingEntity livingEntity) {
 | 
			
		||||
        if (!Config.getInstance().getCallOfTheWildEffectEnabled()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.MOBSPAWNER_FLAMES, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void playAbilityEnabledEffect(Player player) {
 | 
			
		||||
        if (!Config.getInstance().getAbilityActivationEffectEnabled()) {
 | 
			
		||||
            return;
 | 
			
		||||
 
 | 
			
		||||
@@ -353,21 +353,26 @@ Skills:
 | 
			
		||||
            # Item_Material: Material of the item needed to summon the pet
 | 
			
		||||
            # Item_Amount: Amount of items required to summon the pet
 | 
			
		||||
            # Summon_Amount: Amount of pets to summon when using Call Of The Wild
 | 
			
		||||
            # Summon_Length: Pets despawn when their summon life length expires
 | 
			
		||||
            Wolf:
 | 
			
		||||
                Item_Material: BONE
 | 
			
		||||
                Item_Amount: 10
 | 
			
		||||
                Summon_Amount: 1
 | 
			
		||||
                Summon_Length: 240
 | 
			
		||||
            Ocelot:
 | 
			
		||||
                Item_Material: RAW_FISH
 | 
			
		||||
                Item_Amount: 10
 | 
			
		||||
                Summon_Amount: 1
 | 
			
		||||
                Summon_Length: 240
 | 
			
		||||
            Horse:
 | 
			
		||||
                Item_Material: APPLE
 | 
			
		||||
                Item_Amount: 10
 | 
			
		||||
                Summon_Amount: 1
 | 
			
		||||
                Summon_Length: 240
 | 
			
		||||
 | 
			
		||||
            # Range to check for nearby pets when using Call Of The Wild, 0 will disable the check
 | 
			
		||||
            Range: 40.0
 | 
			
		||||
 | 
			
		||||
    Unarmed:
 | 
			
		||||
        Enabled_For_PVP: true
 | 
			
		||||
        Enabled_For_PVE: true
 | 
			
		||||
@@ -473,6 +478,7 @@ Particles:
 | 
			
		||||
    Dodge: true
 | 
			
		||||
    Bleed: true
 | 
			
		||||
    Greater_Impact: true
 | 
			
		||||
    Call_of_the_Wild: true
 | 
			
		||||
 | 
			
		||||
    # These settings determine if fireworks should get launched when a player levels-up,
 | 
			
		||||
    # this will happen by default for every 100 levels.
 | 
			
		||||
 
 | 
			
		||||
@@ -360,6 +360,7 @@ Taming.Listener=Taming:
 | 
			
		||||
Taming.SkillName=TAMING
 | 
			
		||||
Taming.Skillup=[[YELLOW]]Taming skill increased by {0}. Total ({1})
 | 
			
		||||
Taming.Summon.Complete=[[GREEN]]Summoning complete
 | 
			
		||||
Taming.Summon.Lifespan=[[YELLOW]] (Lifespan: {0}s)
 | 
			
		||||
Taming.Summon.Fail.Ocelot=[[RED]]You have too many ocelots nearby to summon any more.
 | 
			
		||||
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.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user