Partially finished merge

This commit is contained in:
nossr50
2019-08-20 11:24:47 -04:00
119 changed files with 2592 additions and 961 deletions

View File

@@ -1,22 +1,25 @@
package com.gmail.nossr50.skills.taming;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
import com.gmail.nossr50.datatypes.skills.behaviours.TamingBehaviour;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.TamingSummon;
import com.gmail.nossr50.mcMMO;
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.random.RandomChanceSkillStatic;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
@@ -25,72 +28,79 @@ import java.util.HashMap;
import java.util.List;
public class TamingManager extends SkillManager {
private HashMap<EntityType, List<TrackedTamingEntity>> summonedEntities = new HashMap<>();
//TODO: Temporary cache, will be changed in 2.2
private long lastSummonTimeStamp;
private TamingBehaviour tamingBehaviour;
private HashMap<CallOfTheWildType, List<TrackedTamingEntity>> playerSummonedEntities;
public TamingManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
super(pluginRef, mcMMOPlayer, PrimarySkillType.TAMING);
init();
}
protected void addToTracker(LivingEntity livingEntity) {
TrackedTamingEntity trackedEntity = new TrackedTamingEntity(livingEntity);
//TODO: Hacky stuff for 2.1, will be cleaned up in 2.2
private void init() {
//Init Behaviour
tamingBehaviour = new TamingBehaviour(pluginRef);
if (!summonedEntities.containsKey(livingEntity.getType())) {
summonedEntities.put(livingEntity.getType(), new ArrayList<>());
//prevents accidentally summoning too many things when holding down left click
lastSummonTimeStamp = 0L;
//Init per-player tracking of summoned entities
initPerPlayerSummonTracking();
}
private void initPerPlayerSummonTracking() {
playerSummonedEntities = new HashMap<>();
for(CallOfTheWildType callOfTheWildType : CallOfTheWildType.values()) {
playerSummonedEntities.put(callOfTheWildType, new ArrayList<TrackedTamingEntity>());
}
summonedEntities.get(livingEntity.getType()).add(trackedEntity);
}
protected List<TrackedTamingEntity> getTrackedEntities(EntityType entityType) {
return summonedEntities.get(entityType);
}
protected void removeFromTracker(TrackedTamingEntity trackedEntity) {
summonedEntities.get(trackedEntity.getLivingEntity().getType()).remove(trackedEntity);
}
public boolean canUseThickFur() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_THICK_FUR)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_THICK_FUR);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_THICK_FUR);
}
public boolean canUseEnvironmentallyAware() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_ENVIRONMENTALLY_AWARE)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_ENVIRONMENTALLY_AWARE);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_ENVIRONMENTALLY_AWARE);
}
public boolean canUseShockProof() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_SHOCK_PROOF)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_SHOCK_PROOF);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_SHOCK_PROOF);
}
public boolean canUseHolyHound() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_ENVIRONMENTALLY_AWARE)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_HOLY_HOUND);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_HOLY_HOUND);
}
public boolean canUseFastFoodService() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_FAST_FOOD_SERVICE)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_FAST_FOOD_SERVICE);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_FAST_FOOD_SERVICE);
}
public boolean canUseSharpenedClaws() {
return pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_SHARPENED_CLAWS)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_SHARPENED_CLAWS);
&& pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_SHARPENED_CLAWS);
}
public boolean canUseGore() {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_GORE))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_GORE))
return false;
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_GORE);
return pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_GORE);
}
public boolean canUseBeastLore() {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_BEAST_LORE))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_BEAST_LORE))
return false;
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_BEAST_LORE);
return pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.TAMING_BEAST_LORE);
}
/**
@@ -99,17 +109,16 @@ public class TamingManager extends SkillManager {
* @param entity The LivingEntity to award XP for
*/
public void awardTamingXP(LivingEntity entity) {
applyXpGain(pluginRef.getDynamicSettingsManager().getExperienceManager().getTamingXp(entity.getType()), XPGainReason.PVE);
applyXpGain(ExperienceConfig.getInstance().getTamingXP(entity.getType()), XPGainReason.PVE);
}
/**
* Apply the Fast Food Service ability.
*
* @param wolf The wolf using the ability
* @param wolf The wolf using the ability
* @param damage The damage being absorbed by the wolf
*/
public void fastFoodService(Wolf wolf, double damage) {
//chance (3rd param)
if (!pluginRef.getRandomChanceTools().isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.TAMING_FAST_FOOD_SERVICE, getPlayer())) {
return;
}
@@ -134,62 +143,66 @@ public class TamingManager extends SkillManager {
return 0;
}
pluginRef.getBleedTimerTask().add(target, getPlayer(), Taming.getInstance().getGoreBleedTicks(), 1, 2);
pluginRef.getBleedTimerTask().add(target, getPlayer(), pluginRef.getConfigManager().getConfigTaming().getSubSkills().getGore().getGoreBleedTicks(), 1, 2);
if (target instanceof Player) {
pluginRef.getNotificationManager().sendPlayerInformation((Player) target, NotificationType.SUBSKILL_MESSAGE, "Combat.StruckByGore");
pluginRef.getNotificationManager().sendPlayerInformation((Player)target, NotificationType.SUBSKILL_MESSAGE, "Combat.StruckByGore");
}
pluginRef.getNotificationManager().sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Combat.Gore");
damage = (damage * Taming.getInstance().getGoreModifier()) - damage;
damage = (damage * pluginRef.getConfigManager().getConfigTaming().getSubSkills().getGore().getGoreMofifier()) - damage;
return damage;
}
public double getSharpenedClawsDamage() {
return Taming.getInstance().getSharpenedClawsBonusDamage();
//TODO: Add tooltips to /taming for this
public double sharpenedClaws(boolean PVE) {
if(PVE)
return pluginRef.getConfigManager().getConfigTaming().getSubSkills().getSharpenedClaws().getBonusDamage().getPVEModifier();
else
return pluginRef.getConfigManager().getConfigTaming().getSubSkills().getSharpenedClaws().getBonusDamage().getPVPModifier();
}
/**
* Summon an ocelot to your side.
*/
public void summonOcelot() {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
return;
if (!Permissions.callOfTheWild(getPlayer(), EntityType.OCELOT)) {
if (!pluginRef.getPermissionTools().callOfTheWild(getPlayer(), EntityType.OCELOT)) {
return;
}
callOfTheWild(EntityType.OCELOT, MainConfig.getInstance().getTamingCOTWCost(EntityType.OCELOT));
processCallOfTheWild();
}
/**
* Summon a wolf to your side.
*/
public void summonWolf() {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
return;
if (!Permissions.callOfTheWild(getPlayer(), EntityType.WOLF)) {
if (!pluginRef.getPermissionTools().callOfTheWild(getPlayer(), EntityType.WOLF)) {
return;
}
callOfTheWild(EntityType.WOLF, MainConfig.getInstance().getTamingCOTWCost(EntityType.WOLF));
processCallOfTheWild();
}
/**
* Summon a horse to your side.
*/
public void summonHorse() {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_CALL_OF_THE_WILD))
return;
if (!Permissions.callOfTheWild(getPlayer(), EntityType.HORSE)) {
if (!pluginRef.getPermissionTools().callOfTheWild(getPlayer(), EntityType.HORSE)) {
return;
}
callOfTheWild(EntityType.HORSE, MainConfig.getInstance().getTamingCOTWCost(EntityType.HORSE));
processCallOfTheWild();
}
/**
@@ -223,10 +236,10 @@ public class TamingManager extends SkillManager {
}
public void pummel(LivingEntity target, Wolf wolf) {
if (!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_PUMMEL))
if(!pluginRef.getRankTools().hasUnlockedSubskill(getPlayer(), SubSkillType.TAMING_PUMMEL))
return;
if (!pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(AdvancedConfig.getInstance().getPummelChance(), getPlayer(), SubSkillType.TAMING_PUMMEL)))
if(!pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(pluginRef, pluginRef.getDynamicSettingsManager().getSkillPropertiesManager().getStaticChance(SubSkillType.TAMING_PUMMEL), getPlayer(), SubSkillType.TAMING_PUMMEL)))
return;
ParticleEffectUtils.playGreaterImpactEffect(target);
@@ -242,9 +255,11 @@ public class TamingManager extends SkillManager {
}
public void attackTarget(LivingEntity target) {
if (target instanceof Tameable) {
if(target instanceof Tameable)
{
Tameable tameable = (Tameable) target;
if (tameable.getOwner() == getPlayer()) {
if(tameable.getOwner() == getPlayer())
{
return;
}
}
@@ -266,133 +281,258 @@ public class TamingManager extends SkillManager {
}
}
private void processCallOfTheWild() {
//Prevent summoning too many things accidentally if a player holds down the button
if(lastSummonTimeStamp + 150 > System.currentTimeMillis()) {
return;
} else {
lastSummonTimeStamp = System.currentTimeMillis();
}
Player player = getPlayer();
ItemStack itemInMainHand = player.getInventory().getItemInMainHand();
//Check if the item the player is currently holding is a COTW item
if(isCOTWItem(itemInMainHand)) {
//Get the summoning type
CallOfTheWildType callOfTheWildType = pluginRef.getDynamicSettingsManager().getTamingItemManager().getCallType(itemInMainHand.getType());
TamingSummon tamingSummon = tamingBehaviour.getSummon(callOfTheWildType);
//Players will pay for the cost if at least one thing was summoned
int amountSummoned = 0;
//Check to see if players have the correct amount of the item required to summon
if(itemInMainHand.getAmount() >= tamingSummon.getItemAmountRequired()) {
//Initial Spawn location
Location spawnLocation = Misc.getLocationOffset(player.getLocation(), 1);
//COTW can summon multiple entities per usage
for (int i = 0; i < tamingSummon.getEntitiesSummoned(); i++) {
if (getAmountCurrentlySummoned(callOfTheWildType) >= tamingSummon.getSummonCap()) {
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.Limit",
String.valueOf(tamingSummon.getSummonCap()),
StringUtils.getCapitalized(callOfTheWildType.toString()));
break;
}
spawnLocation = Misc.getLocationOffset(spawnLocation, 1);
spawnCOTWEntity(callOfTheWildType, spawnLocation, tamingSummon.getEntityType());
//Inform the player about what they have just done
if (tamingSummon.getSummonLifespan() > 0) {
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.Success.WithLifespan",
StringUtils.getCapitalized(callOfTheWildType.toString()), String.valueOf(tamingSummon.getSummonLifespan()));
} else {
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.Success.WithoutLifespan", StringUtils.getCapitalized(callOfTheWildType.toString()));
}
//Send Sound
SoundManager.sendSound(player, player.getLocation(), SoundType.ABILITY_ACTIVATED_GENERIC);
amountSummoned++;
}
//Remove items from the player if they had at least one entity summoned successfully
if(amountSummoned >= 1) {
//Remove the items used to summon
int itemAmountAfterPayingCost = itemInMainHand.getAmount() - tamingSummon.getItemAmountRequired();
itemInMainHand.setAmount(itemAmountAfterPayingCost);
player.updateInventory();
}
} else {
//Player did not have enough of the item in their main hand
int difference = tamingSummon.getItemAmountRequired() - itemInMainHand.getAmount();
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.NeedMoreItems", String.valueOf(difference), StringUtils.getPrettyItemString(itemInMainHand.getType()));
}
}
}
private void spawnCOTWEntity(CallOfTheWildType callOfTheWildType, Location spawnLocation, EntityType entityType) {
switch(callOfTheWildType) {
case CAT:
//Entity type is needed for cats because in 1.13 and below we spawn ocelots, in 1.14 and above we spawn cats
spawnCat(spawnLocation, entityType);
break;
case HORSE:
spawnHorse(spawnLocation);
break;
case WOLF:
spawnWolf(spawnLocation);
break;
}
}
private void spawnWolf(Location spawnLocation) {
LivingEntity callOfWildEntity = (LivingEntity) getPlayer().getWorld().spawnEntity(spawnLocation, EntityType.WOLF);
//This is used to prevent XP gains for damaging this entity
applyMetaDataToCOTWEntity(callOfWildEntity);
setBaseCOTWEntityProperties(callOfWildEntity);
((Wolf) callOfWildEntity).setAdult();
addToTracker(callOfWildEntity, CallOfTheWildType.WOLF);
//Setup wolf stats
callOfWildEntity.setMaxHealth(20.0);
callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth());
callOfWildEntity.setCustomName(pluginRef.getLocaleManager().getString("Taming.Summon.Name.Format", getPlayer().getName(), StringUtils.getPrettyEntityTypeString(EntityType.WOLF)));
}
private void spawnCat(Location spawnLocation, EntityType entityType) {
LivingEntity callOfWildEntity = (LivingEntity) getPlayer().getWorld().spawnEntity(spawnLocation, entityType);
//This is used to prevent XP gains for damaging this entity
applyMetaDataToCOTWEntity(callOfWildEntity);
setBaseCOTWEntityProperties(callOfWildEntity);
addToTracker(callOfWildEntity, CallOfTheWildType.CAT);
//Randomize the cat
if(callOfWildEntity instanceof Ocelot) {
int numberOfTypes = Ocelot.Type.values().length;
((Ocelot) callOfWildEntity).setCatType(Ocelot.Type.values()[Misc.getRandom().nextInt(numberOfTypes)]);
((Ocelot) callOfWildEntity).setAdult();
} else if(callOfWildEntity instanceof Cat) {
int numberOfTypes = Cat.Type.values().length;
((Cat) callOfWildEntity).setCatType(Cat.Type.values()[Misc.getRandom().nextInt(numberOfTypes)]);
((Cat) callOfWildEntity).setAdult();
}
callOfWildEntity.setCustomName(pluginRef.getLocaleManager().getString("Taming.Summon.Name.Format", getPlayer().getName(), StringUtils.getPrettyEntityTypeString(entityType)));
//Particle effect
ParticleEffectUtils.playCallOfTheWildEffect(callOfWildEntity);
}
private void spawnHorse(Location spawnLocation) {
LivingEntity callOfWildEntity = (LivingEntity) getPlayer().getWorld().spawnEntity(spawnLocation, EntityType.HORSE);
applyMetaDataToCOTWEntity(callOfWildEntity);
setBaseCOTWEntityProperties(callOfWildEntity);
addToTracker(callOfWildEntity, CallOfTheWildType.HORSE);
//Randomize Horse
Horse horse = (Horse) callOfWildEntity;
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(pluginRef.getConfigManager().getConfigTaming().getMinHorseJumpStrength(),
Math.min(Math.min(Misc.getRandom().nextDouble(), Misc.getRandom().nextDouble()) * 2, pluginRef.getConfigManager().getConfigTaming().getMaxHorseJumpStrength())));
horse.setAdult();
//TODO: setSpeed, once available
callOfWildEntity.setCustomName(pluginRef.getLocaleManager().getString("Taming.Summon.Name.Format", getPlayer().getName(), StringUtils.getPrettyEntityTypeString(EntityType.HORSE)));
//Particle effect
ParticleEffectUtils.playCallOfTheWildEffect(callOfWildEntity);
}
private void setBaseCOTWEntityProperties(LivingEntity callOfWildEntity) {
((Tameable) callOfWildEntity).setOwner(getPlayer());
callOfWildEntity.setRemoveWhenFarAway(false);
}
private void applyMetaDataToCOTWEntity(LivingEntity callOfWildEntity) {
//This is used to prevent XP gains for damaging this entity
callOfWildEntity.setMetadata(MetadataConstants.UNNATURAL_MOB_METAKEY, MetadataConstants.metadataValue);
//This helps identify the entity as being summoned by COTW
callOfWildEntity.setMetadata(MetadataConstants.COTW_TEMPORARY_SUMMON, MetadataConstants.metadataValue);
}
/**
* Handle the Call of the Wild ability.
*
* @param type The type of entity to summon.
* @param summonAmount The amount of material needed to summon the entity
* Whether or not the itemstack is used for COTW
* @param itemStack target ItemStack
* @return true if it is used for any COTW
*/
private void callOfTheWild(EntityType type, int summonAmount) {
Player player = getPlayer();
ItemStack heldItem = player.getInventory().getItemInMainHand();
int heldItemAmount = heldItem.getAmount();
Location location = player.getLocation();
if (heldItemAmount < summonAmount) {
int moreAmount = summonAmount - heldItemAmount;
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.NotEnough", String.valueOf(moreAmount), StringUtils.getPrettyItemString(heldItem.getType()));
return;
}
if (!rangeCheck(type)) {
return;
}
int amount = MainConfig.getInstance().getTamingCOTWAmount(type);
int tamingCOTWLength = MainConfig.getInstance().getTamingCOTWLength(type);
for (int i = 0; i < amount; i++) {
if (!summonAmountCheck(type)) {
return;
}
location = Misc.getLocationOffset(location, 1);
LivingEntity callOfWildEntity = (LivingEntity) player.getWorld().spawnEntity(location, type);
FakeEntityTameEvent event = new FakeEntityTameEvent(callOfWildEntity, player);
pluginRef.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
callOfWildEntity.setMetadata(MetadataConstants.UNNATURAL_MOB_METAKEY, MetadataConstants.metadataValue);
((Tameable) callOfWildEntity).setOwner(player);
callOfWildEntity.setRemoveWhenFarAway(false);
addToTracker(callOfWildEntity);
switch (type) {
case OCELOT:
((Ocelot) callOfWildEntity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]);
break;
case WOLF:
callOfWildEntity.setMaxHealth(20.0);
callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth());
break;
case HORSE:
Horse horse = (Horse) callOfWildEntity;
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())));
//TODO: setSpeed, once available
break;
default:
break;
}
if (Permissions.renamePets(player)) {
callOfWildEntity.setCustomName(pluginRef.getLocaleManager().getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
}
ParticleEffectUtils.playCallOfTheWildEffect(callOfWildEntity);
}
ItemStack leftovers = new ItemStack(heldItem);
leftovers.setAmount(heldItemAmount - summonAmount);
player.getInventory().setItemInMainHand(heldItemAmount == summonAmount ? null : leftovers);
String lifeSpan = "";
if (tamingCOTWLength > 0) {
lifeSpan = pluginRef.getLocaleManager().getString("Taming.Summon.Lifespan", tamingCOTWLength);
}
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Taming.Summon.Complete", lifeSpan);
player.playSound(location, Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR, 1F, 0.5F);
public boolean isCOTWItem(ItemStack itemStack) {
return pluginRef.getDynamicSettingsManager().getTamingItemManager().isCOTWItem(itemStack.getType());
}
private boolean rangeCheck(EntityType type) {
double range = MainConfig.getInstance().getTamingCOTWRange();
Player player = getPlayer();
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
private int getAmountCurrentlySummoned(CallOfTheWildType callOfTheWildType) {
//The tracker is unreliable so validate its contents first
recalibrateTracker();
if (range == 0) {
return true;
return playerSummonedEntities.get(callOfTheWildType).size();
}
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
private void addToTracker(LivingEntity livingEntity, CallOfTheWildType callOfTheWildType) {
TrackedTamingEntity trackedEntity = new TrackedTamingEntity(pluginRef, livingEntity, callOfTheWildType, this);
playerSummonedEntities.get(callOfTheWildType).add(trackedEntity);
}
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
public List<TrackedTamingEntity> getTrackedEntities(CallOfTheWildType callOfTheWildType) {
return playerSummonedEntities.get(callOfTheWildType);
}
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
public void removeFromTracker(TrackedTamingEntity trackedEntity) {
if(playerSummonedEntities.get(trackedEntity.getCallOfTheWildType()).contains(trackedEntity))
playerSummonedEntities.get(trackedEntity.getCallOfTheWildType()).remove(trackedEntity);
pluginRef.getNotificationManager().sendPlayerInformationChatOnly(getPlayer(), "Taming.Summon.COTW.TimeExpired", StringUtils.getPrettyEntityTypeString(trackedEntity.getLivingEntity().getType()));
}
/**
* Builds a new tracked list by determining which tracked things are still valid
*/
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
private void recalibrateTracker() {
for(CallOfTheWildType callOfTheWildType : CallOfTheWildType.values()) {
ArrayList<TrackedTamingEntity> validEntities = getValidTrackedEntities(callOfTheWildType);
playerSummonedEntities.put(callOfTheWildType, validEntities); //Replace the old list with the new list
}
}
for (Entity entity : player.getNearbyEntities(range, range, range)) {
if (entity.getType() == type) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, Taming.getInstance().getCallOfTheWildFailureMessage(type));
return false;
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
private ArrayList<TrackedTamingEntity> getValidTrackedEntities(CallOfTheWildType callOfTheWildType) {
ArrayList<TrackedTamingEntity> validTrackedEntities = new ArrayList<>();
for(TrackedTamingEntity trackedTamingEntity : getTrackedEntities(callOfTheWildType)) {
LivingEntity livingEntity = trackedTamingEntity.getLivingEntity();
//Remove from existence
if(livingEntity != null && livingEntity.isValid()) {
validTrackedEntities.add(trackedTamingEntity);
}
}
return true;
return validTrackedEntities;
}
private boolean summonAmountCheck(EntityType entityType) {
Player player = getPlayer();
/**
* Remove all tracked entities from existence if they currently exist
* Clear the tracked entity lists afterwards
*/
//TODO: The way this tracker was written is garbo, I should just rewrite it, I'll save that for a future update
public void cleanupAllSummons() {
for(List<TrackedTamingEntity> trackedTamingEntities : playerSummonedEntities.values()) {
for(TrackedTamingEntity trackedTamingEntity : trackedTamingEntities) {
LivingEntity livingEntity = trackedTamingEntity.getLivingEntity();
int maxAmountSummons = MainConfig.getInstance().getTamingCOTWMaxAmount(entityType);
//Remove from existence
if(livingEntity != null && livingEntity.isValid()) {
livingEntity.setHealth(0);
livingEntity.remove();
}
}
if (maxAmountSummons <= 0) {
return true;
//Clear the list
trackedTamingEntities.clear();
}
List<TrackedTamingEntity> trackedEntities = getTrackedEntities(entityType);
int summonAmount = trackedEntities == null ? 0 : trackedEntities.size();
if (summonAmount >= maxAmountSummons) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Taming.Summon.Fail.TooMany", String.valueOf(maxAmountSummons));
return false;
}
return true;
}
}

View File

@@ -1,26 +1,31 @@
package com.gmail.nossr50.skills.taming;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
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 java.util.UUID;
public class TrackedTamingEntity extends BukkitRunnable {
private LivingEntity livingEntity;
private final CallOfTheWildType callOfTheWildType;
private UUID id;
private int length;
private final TamingManager tamingManagerRef;
private final mcMMO pluginRef;
protected TrackedTamingEntity(LivingEntity livingEntity) {
protected TrackedTamingEntity(mcMMO pluginRef, LivingEntity livingEntity, CallOfTheWildType callOfTheWildType, TamingManager tamingManagerRef) {
this.tamingManagerRef = tamingManagerRef;
this.callOfTheWildType = callOfTheWildType;
this.livingEntity = livingEntity;
this.id = livingEntity.getUniqueId();
int tamingCOTWLength = MainConfig.getInstance().getTamingCOTWLength(livingEntity.getType());
int tamingCOTWLength = pluginRef.getConfigManager().getConfigTaming().getSubSkills().getCallOfTheWild()..getTamingCOTWLength(livingEntity.getType());
if (tamingCOTWLength > 0) {
this.length = tamingCOTWLength * Misc.TICK_CONVERSION_FACTOR;
@@ -35,17 +40,26 @@ public class TrackedTamingEntity extends BukkitRunnable {
location.getWorld().playSound(location, Sound.BLOCK_FIRE_EXTINGUISH, 0.8F, 0.8F);
ParticleEffectUtils.playCallOfTheWildEffect(livingEntity);
pluginRef.getCombatTools().dealDamage(livingEntity, livingEntity.getMaxHealth(), DamageCause.SUICIDE, livingEntity);
if(tamingManagerRef != null)
tamingManagerRef.removeFromTracker(this);
livingEntity.setHealth(0);
livingEntity.remove();
}
TamingManager.removeFromTracker(this);
this.cancel();
}
protected LivingEntity getLivingEntity() {
public CallOfTheWildType getCallOfTheWildType() {
return callOfTheWildType;
}
public LivingEntity getLivingEntity() {
return livingEntity;
}
protected UUID getID() {
public UUID getID() {
return id;
}
}