mirror of
https://github.com/shansen/EggCatcher.git
synced 2024-11-29 05:26:15 +01:00
Formatting, cleanup, and jdocs
This commit is contained in:
parent
998073659b
commit
ece246d7d8
@ -214,14 +214,28 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.logCaptures) {
|
if (this.logCaptures) {
|
||||||
captureLogger.logToFile("Player " + ((Player) egg.getShooter()).getName() + " caught " + entity.getType() + " at X" + Math.round(entity.getLocation().getX()) + ",Y" + Math.round(entity.getLocation().getY()) + ",Z" + Math.round(entity.getLocation().getZ()));
|
captureLogger.logToFile(String.format("Player %s caught %s at X%d,Y%d,Z%d",
|
||||||
|
((Player) egg.getShooter()).getName(),
|
||||||
|
entity.getType().toString(),
|
||||||
|
Math.round(entity.getLocation().getX()),
|
||||||
|
Math.round(entity.getLocation().getY()),
|
||||||
|
Math.round(entity.getLocation().getZ())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the player satisfies requirements necessary to capture mob
|
||||||
|
*
|
||||||
|
* @param event egg capture event
|
||||||
|
* @param player player causing event
|
||||||
|
* @param vaultCost economy cost to capture mob
|
||||||
|
* @param itemCost item cost to capture mob
|
||||||
|
* @return if player should catch the mob
|
||||||
|
*/
|
||||||
private boolean playerHasRequirements(EggCaptureEvent event, Player player, double vaultCost, ItemStack itemCost) {
|
private boolean playerHasRequirements(EggCaptureEvent event, Player player, double vaultCost, ItemStack itemCost) {
|
||||||
LivingEntity entity = (LivingEntity) event.getEntity();
|
LivingEntity entity = (LivingEntity) event.getEntity();
|
||||||
String eggType = Objects.requireNonNull(EggType.getEggType(event.getEntity())).getFriendlyName();
|
String eggType = Objects.requireNonNull(EggType.getEggType(event.getEntity())).getFriendlyName();
|
||||||
double entityHealthRequirement = getEntityHealthRequirement(entity, eggType);
|
double entityHealthRequirement = getEntityHealthRequirement(eggType);
|
||||||
|
|
||||||
String message = null;
|
String message = null;
|
||||||
boolean hasRequirements = true;
|
boolean hasRequirements = true;
|
||||||
@ -260,10 +274,24 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
return hasRequirements;
|
return hasRequirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the vault (economy) cost of capturing the given egg mob
|
||||||
|
*
|
||||||
|
* @param p player attempting to capture mob
|
||||||
|
* @param eggType friendly name of the mob egg being caught
|
||||||
|
* @return vault cost of capturing the mob egg
|
||||||
|
*/
|
||||||
private double getVaultCost(Player p, String eggType) {
|
private double getVaultCost(Player p, String eggType) {
|
||||||
return this.useVaultCost && !p.hasPermission("eggcatcher.free") ? config.getDouble("VaultCost." + eggType) : 0;
|
return this.useVaultCost && !p.hasPermission("eggcatcher.free") ? config.getDouble("VaultCost." + eggType) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the item cost of catching a mob egg
|
||||||
|
*
|
||||||
|
* @param p player attempting to capture mob
|
||||||
|
* @param eggType friendly name of the mob egg being caught
|
||||||
|
* @return item cost of capturing the mob egg
|
||||||
|
*/
|
||||||
private ItemStack getItemCost(Player p, String eggType) {
|
private ItemStack getItemCost(Player p, String eggType) {
|
||||||
if (this.useItemCost && !p.hasPermission("eggcatcher.free")) {
|
if (this.useItemCost && !p.hasPermission("eggcatcher.free")) {
|
||||||
int itemId = config.getInt("ItemCost.ItemId", 266);
|
int itemId = config.getInt("ItemCost.ItemId", 266);
|
||||||
@ -274,18 +302,42 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getEntityHealthRequirement(LivingEntity entity, String eggType) {
|
/**
|
||||||
|
* Get the required health percentage to catch given mob egg
|
||||||
|
*
|
||||||
|
* @param eggType friendly name of mob egg type being caught
|
||||||
|
* @return required health percentage to catch given mob egg
|
||||||
|
*/
|
||||||
|
private double getEntityHealthRequirement(String eggType) {
|
||||||
return this.useHealthPercentage ? config.getDouble("HealthPercentage." + eggType) : 0;
|
return this.useHealthPercentage ? config.getDouble("HealthPercentage." + eggType) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current percentage of max health an entity currently has
|
||||||
|
*
|
||||||
|
* @param entity Entity to get health percentage of
|
||||||
|
* @return current percentage of max health an entity currently has
|
||||||
|
*/
|
||||||
private double getEntityHealthPercentage(LivingEntity entity) {
|
private double getEntityHealthPercentage(LivingEntity entity) {
|
||||||
return entity.getHealth() * 100.0 / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
return entity.getHealth() * 100.0 / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the EntityDamageByEntityEvent is damage done by a valid egg to a valid egg-able mob
|
||||||
|
*
|
||||||
|
* @param e EntityDamageByEntityEvent
|
||||||
|
* @return if this event is a valid egg capture
|
||||||
|
*/
|
||||||
private boolean checkIsEggEvent(EntityDamageByEntityEvent e) {
|
private boolean checkIsEggEvent(EntityDamageByEntityEvent e) {
|
||||||
return e.getDamager() instanceof Egg && EggType.getEggType(e.getEntity()) != null;
|
return e.getDamager() instanceof Egg && EggType.getEggType(e.getEntity()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the entity being damaged satisfies the configured baby/tamed/sheared restrictions
|
||||||
|
*
|
||||||
|
* @param e entity damage by entity event
|
||||||
|
* @return if the entity being damated satisfies the restrictions
|
||||||
|
*/
|
||||||
private boolean checkAnimalRestrictions(EntityDamageByEntityEvent e) {
|
private boolean checkAnimalRestrictions(EntityDamageByEntityEvent e) {
|
||||||
Entity entity = e.getEntity();
|
Entity entity = e.getEntity();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user