Skip to content

Commit

Permalink
Cleaned Javadoc + Method depreaction
Browse files Browse the repository at this point in the history
Wow, most uses of CompatibillityAdapter#attackEntity are just to check permissions.

Also sneaked in a minor bugfix, but shh
  • Loading branch information
Geolykt committed Nov 6, 2020
1 parent c13c752 commit c9cb2b5
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public void onImpact() {
100 * getLevel(), .1f, getLevel(), 1.5f, getLevel());
for (Entity e : arrow.getNearbyEntities(aoe, aoe, aoe)) {
if (e instanceof LivingEntity && !e.equals(arrow.getShooter())
&& Storage.COMPATIBILITY_ADAPTER.attackEntity(
(LivingEntity) e, (Player) arrow.getShooter(), 0)) {
&& Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) e, (Player) arrow.getShooter(), 0, false)) {
Utilities.addPotion((LivingEntity) e, SLOW, (int) Math.round(50 + getLevel()
* getPower() * 50), (int) Math.round(getLevel() * getPower() * 2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onImpact() {
for (Entity e : arrow.getNearbyEntities(aoe, aoe, aoe)) {
if (e instanceof LivingEntity && !e.equals(arrow.getShooter())
&& Storage.COMPATIBILITY_ADAPTER.attackEntity(
(LivingEntity) e, (Player) arrow.getShooter(), 0)) {
(LivingEntity) e, (Player) arrow.getShooter(), 0, false)) {
e.setFireTicks((int) Math.round(getLevel() * getPower() * 100));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public void onImpact() {

public boolean onImpact(EntityDamageByEntityEvent evt) {
Location l = evt.getEntity().getLocation();
if (Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) arrow.getShooter(),
0)) {
if (Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) arrow.getShooter(), 0, false)) {
if (evt.getEntity().getType().equals(EntityType.CREEPER)) {
Creeper c = (Creeper) evt.getEntity();
Storage.COMPATIBILITY_ADAPTER.explodeCreeper(c, Config.get(evt.getDamager().getWorld()).explosionBlockBreak());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ReaperArrow(AbstractArrow entity, int level, double power) {

public boolean onImpact(EntityDamageByEntityEvent evt) {
if (Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) arrow.getShooter(),
0)) {
0, false)) {
int pow = (int) Math.round(getLevel() * getPower());
int dur = (int) Math.round(20 + getLevel() * 10 * getPower());
Utilities.addPotion((LivingEntity) evt.getEntity(), PotionEffectType.WITHER, dur, pow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SiphonArrow(AbstractArrow entity, int level, double power) {
public boolean onImpact(EntityDamageByEntityEvent evt) {
if (evt.getEntity() instanceof LivingEntity && Storage.COMPATIBILITY_ADAPTER.attackEntity(
(LivingEntity) evt.getEntity(),
(Player) arrow.getShooter(), 0)) {
(Player) arrow.getShooter(), 0, false)) {
Player player = (Player) ((Projectile) evt.getDamager()).getShooter();
double difference = 0;
if (Siphon.calcAmour) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public StationaryArrow(AbstractArrow entity) {

public boolean onImpact(EntityDamageByEntityEvent evt) {
if (Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) arrow.getShooter(),
0)) {
0, false)) {
LivingEntity ent = (LivingEntity) evt.getEntity();
if (evt.getDamage() < ent.getHealth()) {
evt.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ToxicArrow(AbstractArrow entity, int level, double power) {

public boolean onImpact(final EntityDamageByEntityEvent evt) {
if (Storage.COMPATIBILITY_ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) arrow.getShooter(),
0)) {
0, false)) {
final int value = (int) Math.round(getLevel() * getPower());
Utilities.addPotion((LivingEntity) evt.getEntity(), CONFUSION, 80 + 60 * value, 4);
Utilities.addPotion((LivingEntity) evt.getEntity(), HUNGER, 40 + 60 * value, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public EnumMap<Material, Material> spectralConversionMap() {
* This has the side effect that items that do not have durability will break instantly.
* @param player The player that should be targeted
* @param damage The amount of damage that should be applied
* @param slotIndex The index of the item within the inventory
* @param handUsed True if the mainhand should be damaged, false if the offhand should be damaged
* @since 1.0
*/
public static void damageTool(Player player, int damage, boolean handUsed) {
Expand Down Expand Up @@ -397,6 +397,7 @@ public static boolean damageItem2(ItemStack stack, int damage) {
|| stack.getItemMeta() == null
|| !(stack.getItemMeta() instanceof Damageable)
|| stack.getItemMeta().isUnbreakable()) {
return false;
}
// chance that the item is broken is 1/(level+1)
// So at level = 2 it's 33%, at level = 0 it's 100%, at level 1 it's 50%, at level = 3 it's 25%
Expand Down Expand Up @@ -475,11 +476,12 @@ public static void setDamage(ItemStack is, int damage) {
}

/**
* Sets the amount of Damage that a given ItemStack has (which is the inverse of the remaining durability). <br>
* Gets the amount of Damage that a given ItemStack has (which is the inverse of the remaining durability). <br>
* If the ItemMeta of the ItemStack is not a {@link org.bukkit.inventory.meta.Damageable} instance then 0 will be returned. <br>
* Does not check whether the itemstack has the unbreakable flag set, caution is advised.
* @param is The target itemstack
* @param damage The value that the damage should now have
* @return The amount of damage an ItemStack has.
* @since 1.0
*/
public static int getDamage(ItemStack is) {
Expand Down Expand Up @@ -563,10 +565,15 @@ public boolean placeBlock(Block blockPlaced, Player player, ItemStack is) {
}

/**
*
* @return True if damaged, false otherwise
* @deprecated This method does not specify the tool that should be broken.
* Queries whether the player is allowed to damage the target, damages it and breaks the mainhand tool.
* @param target The target that should be attacked
* @param attacker The player that attacks the target
* @param damage The damage that should be dealt in half hearts
* @return True if performed without issues, false otherwise
* @since 1.0
*/
@Deprecated
public boolean attackEntity(LivingEntity target, Player attacker, double damage) {
return attackEntity(target, attacker, damage, true);
}
Expand All @@ -576,8 +583,7 @@ public boolean attackEntity(LivingEntity target, Player attacker, double damage,
Bukkit.getPluginManager().callEvent(damageEvent);
if (damage == 0) {
return !damageEvent.isCancelled();
}
if (!damageEvent.isCancelled()) {
} else if (!damageEvent.isCancelled()) {
target.damage(damage, attacker);
target.setLastDamageCause(damageEvent);
if (performEquipmentDamage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public default boolean hasEnchantment(Config config, ItemStack stk, BaseEnchantm
* In case the enchantment is not found, 0 should be returned.
* @param config The configuration that should be used
* @param stk The stack that should be read
* @param clazz The Enchantment that should be searched for.
* @param ench The Enchantment that should be searched for.
* @return The level of the given enchantment on a given stack.
* @since 2.1.1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void entityPhysics() {

if (targetEntity.getNoDamageTicks() == 0 && attackBlocks.get(blockEntity) != null
&& Storage.COMPATIBILITY_ADAPTER.attackEntity(targetEntity, attacker,
2.0 * attackBlocks.get(blockEntity).getKey())) {
2.0 * attackBlocks.get(blockEntity).getKey(), false)) {
targetEntity.setNoDamageTicks(0);
anthroIterator.remove();
blockEntity.remove();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.geolykt.enchantments_plus.enchantments;

import org.bukkit.GameMode;
import org.bukkit.Particle;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.event.block.BlockBreakEvent;
Expand Down Expand Up @@ -35,9 +34,6 @@ public Builder<Extraction> defaults() {

@Override
public boolean onBlockBreak(BlockBreakEvent evt, final int level, boolean usedHand) {
if (evt.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
return false;
}
if (evt.getBlock().getType() == GOLD_ORE || evt.getBlock().getType() == IRON_ORE) {
CompatibilityAdapter.damageTool(evt.getPlayer(), 1, usedHand);
for (int x = 0; x < ThreadLocalRandom.current().nextInt((int) Math.round(power * level + 1)) + 1; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean onBlockInteract(PlayerInteractEvent evt, int level, boolean usedH
org.bukkit.util.Vector vect = new Vector(total.getX(), total.getY(), total.getZ())
.multiply((.1f + (power * level * .2f)));
vect.setY(vect.getY() > 1 ? 1 : -1);
if (ent instanceof LivingEntity && ADAPTER.attackEntity((LivingEntity) ent, player, 0)) {
if (ent instanceof LivingEntity && ADAPTER.attackEntity((LivingEntity) ent, player, 0, false)) {
ent.setVelocity(vect);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import de.geolykt.enchantments_plus.CustomEnchantment;
import de.geolykt.enchantments_plus.EnchantPlayer;
import de.geolykt.enchantments_plus.compatibility.CompatibilityAdapter;
import de.geolykt.enchantments_plus.enums.BaseEnchantments;
import de.geolykt.enchantments_plus.enums.Hand;
import de.geolykt.enchantments_plus.util.Tool;
Expand Down Expand Up @@ -69,7 +70,8 @@ public void shoot(Player player, int level, boolean usedHand) {
for (Entity ent : Bukkit.getWorld(playLoc.getWorld().getName()).getNearbyEntities(tempLoc, .3, .3, .3)) {
if (ent instanceof LivingEntity && ent != player) {
LivingEntity e = (LivingEntity) ent;
ADAPTER.attackEntity(e, player, 1 + (level + power * 2));
ADAPTER.attackEntity(e, player, 1 + (level + power * 2), false);
CompatibilityAdapter.damageTool(player, 1, usedHand);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Builder<RainbowSlam> defaults() {
@Override
public boolean onEntityInteract(final PlayerInteractEntityEvent evt, final int level, boolean usedHand) {
if (!(evt.getRightClicked() instanceof LivingEntity) ||
!ADAPTER.attackEntity((LivingEntity) evt.getRightClicked(), evt.getPlayer(), 0)) {
!ADAPTER.attackEntity((LivingEntity) evt.getRightClicked(), evt.getPlayer(), 0, false)) {
return false;
}
final LivingEntity ent = (LivingEntity) evt.getRightClicked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean onEntityShootBow(EntityShootBowEvent evt, int level, boolean used
@Override
public boolean onEntityHit(EntityDamageByEntityEvent evt, int level, boolean usedHand) {
if (evt.getEntity() instanceof LivingEntity &&
ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0, false)) {
int pow = (int) Math.round(level * power);
int dur = (int) Math.round(10 + level * 20 * power);
Utilities.addPotion((LivingEntity) evt.getEntity(), PotionEffectType.WITHER, dur, pow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Builder<Siphon> defaults() {
@Override
public boolean onEntityHit(EntityDamageByEntityEvent evt, int level, boolean usedHand) {
if (evt.getEntity() instanceof LivingEntity
&& ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
&& ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0, false)) {
Player player = (Player) evt.getDamager();
double difference = 0;
if (calcAmour) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Builder<Stationary> defaults() {
@Override
public boolean onEntityHit(EntityDamageByEntityEvent evt, int level, boolean usedHand) {
if (!(evt.getEntity() instanceof LivingEntity)
|| ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
|| ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0, false)) {
LivingEntity ent = (LivingEntity) evt.getEntity();
if (evt.getDamage() < ent.getHealth()) {
evt.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean onEntityShootBow(EntityShootBowEvent evt, int level, boolean used
@Override
public boolean onEntityHit(final EntityDamageByEntityEvent evt, int level, boolean usedHand) {
if (!(evt.getEntity() instanceof LivingEntity) ||
!ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
!ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0, false)) {
final int value = (int) Math.round(level * power);
Utilities.addPotion((LivingEntity) evt.getEntity(), CONFUSION, 80 + 60 * value, 4);
Utilities.addPotion((LivingEntity) evt.getEntity(), HUNGER, 40 + 60 * value, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean onEntityHit(EntityDamageByEntityEvent evt, int level, boolean use
return false;
}
if (evt.getEntity() instanceof LivingEntity
&& ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
&& ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0, false)) {
if (ThreadLocalRandom.current().nextInt(100) > (100 - (level * power * 8))) {
LivingEntity newEnt = Storage.COMPATIBILITY_ADAPTER.transformationCycle((LivingEntity) evt.getEntity(),
ThreadLocalRandom.current());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean onBeingHit(EntityDamageByEntityEvent evt, int level, boolean used
if (!(evt.getEntity() instanceof Player) || //check if victim is a player
!(evt.getDamager() instanceof LivingEntity) || //check if the damager is alive
//check if the victim (player) can damage the attacker
!ADAPTER.attackEntity((LivingEntity) evt.getDamager(), (Player) evt.getEntity(), 0)) {
!ADAPTER.attackEntity((LivingEntity) evt.getDamager(), (Player) evt.getEntity(), 0, false)) {
return true;
}
Player player = (Player) evt.getEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void adjustBlock(@NotNull Block newBlock) {
/**
* This variable keeps track on which enchantment invoked the Event, which is useful for 3rd party APIs to check for which reason the query was used.<br>
* By default it's {@link BaseEnchantments#SPECTRAL} and cannot be changed during the object's lifecycle.
* @return The enchantment that has issued the event.
* @since 1.2.1
*/
public BaseEnchantments getUse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface AreaOfEffectable {
* in which the AOE could be affected. <br> Additionally the AOE has the player (or arrow) at it's center and the size
* is the distance between the border of the AOE and the center of the AOE. <br>
* Implementations should ideally make use of {@link #getAOEMultiplier()}.
* @param level The level of the enchantment
* @return The size of the AOE
* @since 2.1.6
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ public static void selfRemovingArea(Material fill, Material check, int radius, B
* found
* @param flipValidSearch true -> validSearch is a allowlist; false ->
* validSearch is a denylist
* @return A list of the Blocks the BFS algorithm found that match the given parameters.
*/
public static List<Block> BFS(Block startBlock, int maxBlocks, boolean strictMax, float maxDistFromOrigin,
int[][] searchFaces, Set<Material> validFind, Set<Material> validSearch, boolean strictValidSearch,
Expand Down

0 comments on commit c9cb2b5

Please sign in to comment.