mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 11:14:44 +02:00
Add lifespan to Taming summons
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user