mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-26 02:28:03 +01:00
More tweaks to Taming.
This commit is contained in:
parent
2d47447375
commit
5ba9fb78fd
@ -9,6 +9,7 @@ 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;
|
||||||
@ -35,7 +36,7 @@ import com.gmail.nossr50.runnables.BleedTimer;
|
|||||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
||||||
import com.gmail.nossr50.skills.combat.Archery;
|
import com.gmail.nossr50.skills.combat.Archery;
|
||||||
import com.gmail.nossr50.skills.gathering.BlastMining;
|
import com.gmail.nossr50.skills.gathering.BlastMining;
|
||||||
import com.gmail.nossr50.skills.taming.Taming;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.util.Combat;
|
import com.gmail.nossr50.util.Combat;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -142,9 +143,11 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
} else if (lEntity instanceof Tameable) {
|
} else if (lEntity instanceof Tameable) {
|
||||||
Tameable pet = (Tameable) lEntity;
|
Tameable pet = (Tameable) lEntity;
|
||||||
|
AnimalTamer owner = pet.getOwner();
|
||||||
|
|
||||||
if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (pet.getOwner() instanceof Player)) {
|
if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (owner instanceof Player) && pet instanceof Wolf) {
|
||||||
Taming.preventDamage(event);
|
TamingManager tamingManager = new TamingManager((Player) owner);
|
||||||
|
tamingManager.preventDamage(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.gmail.nossr50.listeners;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -36,7 +35,7 @@ import com.gmail.nossr50.runnables.BleedTimer;
|
|||||||
import com.gmail.nossr50.skills.gathering.BlastMining;
|
import com.gmail.nossr50.skills.gathering.BlastMining;
|
||||||
import com.gmail.nossr50.skills.gathering.Fishing;
|
import com.gmail.nossr50.skills.gathering.Fishing;
|
||||||
import com.gmail.nossr50.skills.gathering.Herbalism;
|
import com.gmail.nossr50.skills.gathering.Herbalism;
|
||||||
import com.gmail.nossr50.skills.taming.Taming;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.spout.SpoutStuff;
|
import com.gmail.nossr50.spout.SpoutStuff;
|
||||||
import com.gmail.nossr50.util.BlockChecks;
|
import com.gmail.nossr50.util.BlockChecks;
|
||||||
import com.gmail.nossr50.util.Item;
|
import com.gmail.nossr50.util.Item;
|
||||||
@ -291,12 +290,16 @@ public class PlayerListener implements Listener {
|
|||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
|
|
||||||
/* CALL OF THE WILD CHECKS */
|
/* CALL OF THE WILD CHECKS */
|
||||||
if (player.isSneaking() && Permissions.getInstance().taming(player)) {
|
if (player.isSneaking()) {
|
||||||
if (inHand.getType().equals(Material.RAW_FISH)) {
|
Material type = inHand.getType();
|
||||||
Taming.animalSummon(EntityType.OCELOT, player, plugin);
|
|
||||||
|
if (type == Material.RAW_FISH) {
|
||||||
|
TamingManager tamingManager = new TamingManager(player);
|
||||||
|
tamingManager.summonOcelot();
|
||||||
}
|
}
|
||||||
else if (inHand.getType().equals(Material.BONE)) {
|
else if (type == Material.BONE) {
|
||||||
Taming.animalSummon(EntityType.WOLF, player, plugin);
|
TamingManager tamingManager = new TamingManager(player);
|
||||||
|
tamingManager.summonWolf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.entity.AnimalTamer;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
|
||||||
|
public class BeastLoreEventHandler {
|
||||||
|
private Player player;
|
||||||
|
private LivingEntity livingEntity;
|
||||||
|
private Tameable beast;
|
||||||
|
|
||||||
|
protected BeastLoreEventHandler (Player player, LivingEntity livingEntity) {
|
||||||
|
this.player = player;
|
||||||
|
this.livingEntity = livingEntity;
|
||||||
|
this.beast = (Tameable) livingEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendInspectMessage() {
|
||||||
|
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
|
||||||
|
|
||||||
|
if (beast.isTamed()) {
|
||||||
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", new Object[] { getOwnerName() }) + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", new Object[] { livingEntity.getHealth(), livingEntity.getMaxHealth() }));
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of a tameable animal's owner.
|
||||||
|
*
|
||||||
|
* @param beast The animal whose owner's name to get
|
||||||
|
* @return the name of the animal's owner, or "Offline Master" if the owner is offline
|
||||||
|
*/
|
||||||
|
private String getOwnerName() {
|
||||||
|
AnimalTamer tamer = beast.getOwner();
|
||||||
|
|
||||||
|
if (tamer instanceof Player) {
|
||||||
|
return ((Player) tamer).getName();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Offline Master";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
|
public class CallOfTheWildEventHandler {
|
||||||
|
protected Player player;
|
||||||
|
protected ItemStack inHand;
|
||||||
|
protected EntityType type;
|
||||||
|
protected int summonAmount;
|
||||||
|
|
||||||
|
protected CallOfTheWildEventHandler(Player player, EntityType type, int summonAmount) {
|
||||||
|
this.player = player;
|
||||||
|
this.inHand = player.getItemInHand();
|
||||||
|
this.type = type;
|
||||||
|
this.summonAmount = summonAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendInsufficientAmountMessage() {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(inHand.getTypeId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean nearbyEntityExists() {
|
||||||
|
boolean entityExists = false;
|
||||||
|
|
||||||
|
for (Entity entity : player.getNearbyEntities(40, 40, 40)) {
|
||||||
|
if (entity.getType() == type) {
|
||||||
|
entityExists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entityExists;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendFailureMessage() {
|
||||||
|
if (type == EntityType.OCELOT) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Ocelot"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Wolf"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void spawnCreature() {
|
||||||
|
LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
|
||||||
|
entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(mcMMO.p, true));
|
||||||
|
|
||||||
|
((Tameable) entity).setOwner(player);
|
||||||
|
|
||||||
|
if (type == EntityType.OCELOT) {
|
||||||
|
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Taming.getRandom().nextInt(3)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entity.setHealth(entity.getMaxHealth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void processResourceCost() {
|
||||||
|
player.getItemInHand().setAmount(inHand.getAmount() - summonAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendSuccessMessage() {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Wolf;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
|
||||||
|
public class EnvironmentallyAwareEventHandler {
|
||||||
|
private Player player;
|
||||||
|
private EntityDamageEvent event;
|
||||||
|
private Wolf wolf;
|
||||||
|
|
||||||
|
protected EnvironmentallyAwareEventHandler(TamingManager manager, EntityDamageEvent event) {
|
||||||
|
this.player = manager.getPlayer();
|
||||||
|
this.event = event;
|
||||||
|
this.wolf = (Wolf) event.getEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void teleportWolf() {
|
||||||
|
if (event.getDamage() > wolf.getHealth()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wolf.teleport(player.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendAbilityMessage() {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cancelEvent() {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
|
||||||
|
public class ShockProofEventHandler {
|
||||||
|
private EntityDamageEvent event;
|
||||||
|
|
||||||
|
protected ShockProofEventHandler (EntityDamageEvent event) {
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void modifyEventDamage() {
|
||||||
|
event.setDamage(event.getDamage() / Taming.SHOCK_PROOF_MODIFIER);
|
||||||
|
}
|
||||||
|
}
|
@ -2,31 +2,9 @@ package com.gmail.nossr50.skills.taming;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.AnimalTamer;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Ocelot;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Tameable;
|
|
||||||
import org.bukkit.entity.Wolf;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.gmail.nossr50.config.Config;
|
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
import com.gmail.nossr50.util.Misc;
|
|
||||||
import com.gmail.nossr50.util.Permissions;
|
|
||||||
import com.gmail.nossr50.util.Users;
|
|
||||||
|
|
||||||
public class Taming {
|
public class Taming {
|
||||||
|
public static final int ENVIRONMENTALLY_AWARE_ACTIVATION_LEVEL = 100;
|
||||||
|
|
||||||
public static final int FAST_FOOD_SERVICE_ACTIVATION_CHANCE = 50;
|
public static final int FAST_FOOD_SERVICE_ACTIVATION_CHANCE = 50;
|
||||||
public static final int FAST_FOOD_SERVICE_ACTIVATION_LEVEL = 50;
|
public static final int FAST_FOOD_SERVICE_ACTIVATION_LEVEL = 50;
|
||||||
|
|
||||||
@ -37,195 +15,14 @@ public class Taming {
|
|||||||
public static final int SHARPENED_CLAWS_ACTIVATION_LEVEL = 750;
|
public static final int SHARPENED_CLAWS_ACTIVATION_LEVEL = 750;
|
||||||
public static final int SHARPENED_CLAWS_BONUS = 2;
|
public static final int SHARPENED_CLAWS_BONUS = 2;
|
||||||
|
|
||||||
|
public static final int SHOCK_PROOF_ACTIVATION_LEVEL = 500;
|
||||||
|
public static final int SHOCK_PROOF_MODIFIER = 6;
|
||||||
|
|
||||||
|
public static final int THICK_FUR_ACTIVATION_LEVEL = 250;
|
||||||
|
public static final int THICK_FUR_MODIFIER = 2;
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static Random random = new Random();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of a tameable animal's owner.
|
|
||||||
*
|
|
||||||
* @param beast The animal whose owner's name to get
|
|
||||||
* @return the name of the animal's owner, or "Offline Master" if the owner is offline
|
|
||||||
*/
|
|
||||||
private static String getOwnerName(Tameable beast) {
|
|
||||||
AnimalTamer tamer = beast.getOwner();
|
|
||||||
|
|
||||||
if (tamer instanceof Player) {
|
|
||||||
return ((Player) tamer).getName();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "Offline Master";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevent damage to wolves based on various skills.
|
|
||||||
*
|
|
||||||
* @param event The event to modify
|
|
||||||
*/
|
|
||||||
public static void preventDamage(EntityDamageEvent event) {
|
|
||||||
final int ENVIRONMENTALLY_AWARE_LEVEL = 100;
|
|
||||||
final int THICK_FUR_LEVEL = 250;
|
|
||||||
final int SHOCK_PROOF_LEVEL = 500;
|
|
||||||
|
|
||||||
final int THICK_FUR_MODIFIER = 2;
|
|
||||||
final int SHOCK_PROOF_MODIFIER = 6;
|
|
||||||
|
|
||||||
if (!(event.getEntity() instanceof Wolf)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DamageCause cause = event.getCause();
|
|
||||||
Wolf wolf = (Wolf) event.getEntity();
|
|
||||||
Player master = (Player) wolf.getOwner();
|
|
||||||
int skillLevel = Users.getProfile(master).getSkillLevel(SkillType.TAMING);
|
|
||||||
|
|
||||||
switch (cause) {
|
|
||||||
|
|
||||||
/* Environmentally Aware */
|
|
||||||
case CONTACT:
|
|
||||||
case LAVA:
|
|
||||||
case FIRE:
|
|
||||||
if (Permissions.getInstance().environmentallyAware(master)) {
|
|
||||||
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
|
||||||
if (event.getDamage() >= wolf.getHealth()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wolf.teleport(master.getLocation());
|
|
||||||
master.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FALL:
|
|
||||||
if (Permissions.getInstance().environmentallyAware(master)) {
|
|
||||||
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Thick Fur */
|
|
||||||
case FIRE_TICK:
|
|
||||||
if (Permissions.getInstance().thickFur(master)) {
|
|
||||||
if(skillLevel >= THICK_FUR_LEVEL) {
|
|
||||||
wolf.setFireTicks(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ENTITY_ATTACK:
|
|
||||||
case PROJECTILE:
|
|
||||||
if (Permissions.getInstance().thickFur(master)) {
|
|
||||||
if (skillLevel >= THICK_FUR_LEVEL) {
|
|
||||||
event.setDamage(event.getDamage() / THICK_FUR_MODIFIER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Shock Proof */
|
|
||||||
case ENTITY_EXPLOSION:
|
|
||||||
case BLOCK_EXPLOSION:
|
|
||||||
if (Permissions.getInstance().shockProof(master)) {
|
|
||||||
if (skillLevel >= SHOCK_PROOF_LEVEL) {
|
|
||||||
event.setDamage(event.getDamage() / SHOCK_PROOF_MODIFIER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summon an animal.
|
|
||||||
*
|
|
||||||
* @param type Type of animal to summon
|
|
||||||
* @param player Player summoning the animal
|
|
||||||
*/
|
|
||||||
public static void animalSummon(EntityType type, Player player, mcMMO plugin) {
|
|
||||||
ItemStack item = player.getItemInHand();
|
|
||||||
Material summonItem = null;
|
|
||||||
int summonAmount = 0;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case WOLF:
|
|
||||||
summonItem = Material.BONE;
|
|
||||||
summonAmount = Config.getInstance().getTamingCOTWWolfCost();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OCELOT:
|
|
||||||
summonItem = Material.RAW_FISH;
|
|
||||||
summonAmount = Config.getInstance().getTamingCOTWOcelotCost();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.getType().equals(summonItem)) {
|
|
||||||
if (item.getAmount() >= summonAmount) {
|
|
||||||
for (Entity x : player.getNearbyEntities(40, 40, 40)) {
|
|
||||||
if (x.getType().equals(type)) {
|
|
||||||
switch (type) {
|
|
||||||
case WOLF:
|
|
||||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Wolf"));
|
|
||||||
return;
|
|
||||||
|
|
||||||
case OCELOT:
|
|
||||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Ocelot"));
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
|
|
||||||
entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(plugin, true));
|
|
||||||
((Tameable) entity).setOwner(player);
|
|
||||||
|
|
||||||
if (entity.getType().equals(EntityType.OCELOT)) {
|
|
||||||
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + random.nextInt(3)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.getType().equals(EntityType.WOLF)) {
|
|
||||||
entity.setHealth(entity.getMaxHealth());
|
|
||||||
}
|
|
||||||
|
|
||||||
player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));
|
|
||||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(summonItem.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inspect a tameable animal for details.
|
|
||||||
*
|
|
||||||
* @param event Event to modify
|
|
||||||
* @param target Animal to inspect
|
|
||||||
* @param inspector Player inspecting the animal
|
|
||||||
*/
|
|
||||||
public static void beastLore(EntityDamageByEntityEvent event, LivingEntity target, Player inspector) {
|
|
||||||
if (target instanceof Tameable) {
|
|
||||||
Tameable beast = (Tameable) target;
|
|
||||||
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
|
|
||||||
int health = target.getHealth();
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if (beast.isTamed()) {
|
|
||||||
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", new Object[] {getOwnerName(beast)}) + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", new Object[] {health, target.getMaxHealth()}));
|
|
||||||
inspector.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Random getRandom() {
|
public static Random getRandom() {
|
||||||
return random;
|
return random;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package com.gmail.nossr50.skills.taming;
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -14,12 +18,14 @@ public class TamingManager {
|
|||||||
private PlayerProfile profile;
|
private PlayerProfile profile;
|
||||||
private int skillLevel;
|
private int skillLevel;
|
||||||
private Permissions permissionsInstance;
|
private Permissions permissionsInstance;
|
||||||
|
private Config configInstance;
|
||||||
|
|
||||||
public TamingManager (Player player) {
|
public TamingManager (Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.profile = Users.getProfile(player);
|
this.profile = Users.getProfile(player);
|
||||||
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
|
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
|
||||||
this.permissionsInstance = Permissions.getInstance();
|
this.permissionsInstance = Permissions.getInstance();
|
||||||
|
this.configInstance = Config.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,6 +84,138 @@ public class TamingManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent damage to wolves based on various skills.
|
||||||
|
*
|
||||||
|
* @param event The event to modify
|
||||||
|
*/
|
||||||
|
public void preventDamage(EntityDamageEvent event) {
|
||||||
|
DamageCause cause = event.getCause();
|
||||||
|
|
||||||
|
switch (cause) {
|
||||||
|
case CONTACT:
|
||||||
|
case LAVA:
|
||||||
|
case FIRE:
|
||||||
|
case FALL:
|
||||||
|
environmentallyAware(event, cause);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIRE_TICK:
|
||||||
|
case ENTITY_ATTACK:
|
||||||
|
case PROJECTILE:
|
||||||
|
thickFur(event, cause);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENTITY_EXPLOSION:
|
||||||
|
case BLOCK_EXPLOSION:
|
||||||
|
shockProof(event);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summon an ocelot to your side.
|
||||||
|
*/
|
||||||
|
public void summonOcelot() {
|
||||||
|
callOfTheWild(EntityType.OCELOT, configInstance.getTamingCOTWOcelotCost());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summon a wolf to your side.
|
||||||
|
*/
|
||||||
|
public void summonWolf() {
|
||||||
|
callOfTheWild(EntityType.WOLF, configInstance.getTamingCOTWWolfCost());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void beastLore(LivingEntity livingEntity) {
|
||||||
|
if (!permissionsInstance.beastLore(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
|
||||||
|
|
||||||
|
eventHandler.sendInspectMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void callOfTheWild(EntityType type, int summonAmount) {
|
||||||
|
if (!permissionsInstance.callOfTheWild(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(player, type, summonAmount);
|
||||||
|
|
||||||
|
ItemStack inHand = eventHandler.inHand;
|
||||||
|
int inHandAmount = inHand.getAmount();
|
||||||
|
|
||||||
|
if (inHandAmount < summonAmount) {
|
||||||
|
eventHandler.sendInsufficientAmountMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (eventHandler.nearbyEntityExists()) {
|
||||||
|
eventHandler.sendFailureMessage();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
eventHandler.spawnCreature();
|
||||||
|
eventHandler.processResourceCost();
|
||||||
|
eventHandler.sendSuccessMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void environmentallyAware(EntityDamageEvent event, DamageCause cause) {
|
||||||
|
if (!permissionsInstance.environmentallyAware(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skillLevel >= Taming.ENVIRONMENTALLY_AWARE_ACTIVATION_LEVEL) {
|
||||||
|
EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event);
|
||||||
|
|
||||||
|
switch (cause) {
|
||||||
|
case CONTACT:
|
||||||
|
case FIRE:
|
||||||
|
case LAVA:
|
||||||
|
eventHandler.teleportWolf();
|
||||||
|
eventHandler.sendAbilityMessage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FALL:
|
||||||
|
eventHandler.cancelEvent();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void thickFur(EntityDamageEvent event, DamageCause cause) {
|
||||||
|
if (!permissionsInstance.thickFur(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skillLevel >= Taming.THICK_FUR_ACTIVATION_LEVEL) {
|
||||||
|
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
|
||||||
|
|
||||||
|
eventHandler.modifyEventDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shockProof(EntityDamageEvent event) {
|
||||||
|
if (!permissionsInstance.shockProof(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skillLevel >= Taming.SHOCK_PROOF_ACTIVATION_LEVEL) {
|
||||||
|
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
|
||||||
|
|
||||||
|
eventHandler.modifyEventDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected int getSkillLevel() {
|
protected int getSkillLevel() {
|
||||||
return skillLevel;
|
return skillLevel;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.gmail.nossr50.skills.taming;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Wolf;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
|
||||||
|
public class ThickFurEventHandler {
|
||||||
|
private DamageCause cause;
|
||||||
|
private EntityDamageEvent event;
|
||||||
|
private Wolf wolf;
|
||||||
|
|
||||||
|
protected ThickFurEventHandler (EntityDamageEvent event, DamageCause cause) {
|
||||||
|
this.cause = cause;
|
||||||
|
this.event = event;
|
||||||
|
this.wolf = (Wolf) event.getEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void modifyEventDamage() {
|
||||||
|
switch (cause) {
|
||||||
|
case FIRE_TICK:
|
||||||
|
wolf.setFireTicks(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENTITY_ATTACK:
|
||||||
|
case PROJECTILE:
|
||||||
|
event.setDamage(event.getDamage() / Taming.THICK_FUR_MODIFIER);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,7 +34,6 @@ import com.gmail.nossr50.skills.combat.Archery;
|
|||||||
import com.gmail.nossr50.skills.combat.Axes;
|
import com.gmail.nossr50.skills.combat.Axes;
|
||||||
import com.gmail.nossr50.skills.combat.Swords;
|
import com.gmail.nossr50.skills.combat.Swords;
|
||||||
import com.gmail.nossr50.skills.combat.Unarmed;
|
import com.gmail.nossr50.skills.combat.Unarmed;
|
||||||
import com.gmail.nossr50.skills.taming.Taming;
|
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
|
|
||||||
public class Combat {
|
public class Combat {
|
||||||
@ -146,8 +145,10 @@ public class Combat {
|
|||||||
|
|
||||||
startGainXp(attacker, PPa, target, SkillType.UNARMED);
|
startGainXp(attacker, PPa, target, SkillType.UNARMED);
|
||||||
}
|
}
|
||||||
else if (itemInHand.getType().equals(Material.BONE) && permInstance.beastLore(attacker)) {
|
else if (itemInHand.getType() == Material.BONE && target instanceof Tameable) {
|
||||||
Taming.beastLore(event, target, attacker);
|
TamingManager tamingManager = new TamingManager(attacker);
|
||||||
|
tamingManager.beastLore(target);
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (damager instanceof Wolf) {
|
else if (damager instanceof Wolf) {
|
||||||
|
Loading…
Reference in New Issue
Block a user