Improved codestyle (8/?)

This commit is contained in:
Auxilor
2020-12-28 15:20:51 +00:00
parent 186999a701
commit cb191af310
32 changed files with 265 additions and 113 deletions

View File

@@ -11,18 +11,21 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull;
public class PacketChat extends AbstractPacketAdapter {
public PacketChat(AbstractEcoPlugin plugin) {
public PacketChat(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true);
}
@Override
public void onSend(@NotNull PacketContainer packet) {
public void onSend(@NotNull final PacketContainer packet) {
for (int i = 0; i < packet.getChatComponents().size(); i++) {
WrappedChatComponent component = packet.getChatComponents().read(i);
if (component == null)
if (component == null) {
continue;
if (component.getHandle() == null)
}
if (component.getHandle() == null) {
return;
}
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
packet.getChatComponents().write(i, newComponent);
}

View File

@@ -18,18 +18,19 @@ import java.util.List;
import java.util.stream.Collectors;
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
public PacketOpenWindowMerchant(AbstractEcoPlugin plugin) {
public PacketOpenWindowMerchant(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false);
}
@Override
public void onSend(@NotNull PacketContainer packet) {
public void onSend(@NotNull final PacketContainer packet) {
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
recipes = recipes.stream().peek(merchantRecipe -> {
try {
if (!EnchantmentTarget.ALL.getMaterials().contains(merchantRecipe.getResult().getType()))
if (!EnchantmentTarget.ALL.getMaterials().contains(merchantRecipe.getResult().getType())) {
return;
}
// Enables removing final modifier
Field modifiersField = Field.class.getDeclaredField("modifiers");

View File

@@ -8,15 +8,12 @@ import com.willfp.ecoenchants.display.EnchantDisplay;
import org.jetbrains.annotations.NotNull;
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
public PacketSetCreativeSlot(AbstractEcoPlugin plugin) {
public PacketSetCreativeSlot(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false);
}
@Override
public void onReceive(@NotNull PacketContainer packet) {
packet.getItemModifier().modify(0, (item) -> {
item = EnchantDisplay.revertDisplay(item);
return item;
});
public void onReceive(@NotNull final PacketContainer packet) {
packet.getItemModifier().modify(0, EnchantDisplay::revertDisplay);
}
}

View File

@@ -9,17 +9,18 @@ import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
public class PacketSetSlot extends AbstractPacketAdapter {
public PacketSetSlot(AbstractEcoPlugin plugin) {
public PacketSetSlot(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.SET_SLOT, false);
}
@Override
public void onSend(@NotNull PacketContainer packet) {
packet.getItemModifier().modify(0, (item) -> {
public void onSend(@NotNull final PacketContainer packet) {
packet.getItemModifier().modify(0, item -> {
boolean hideEnchants = false;
if (item == null)
return item;
if (item == null) {
return null;
}
if (item.getItemMeta() != null) {
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);

View File

@@ -9,17 +9,20 @@ import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
public class PacketWindowItems extends AbstractPacketAdapter {
public PacketWindowItems(AbstractEcoPlugin plugin) {
public PacketWindowItems(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.WINDOW_ITEMS, false);
}
@Override
public void onSend(@NotNull PacketContainer packet) {
packet.getItemListModifier().modify(0, (itemStacks) -> {
if (itemStacks == null) return null;
public void onSend(@NotNull final PacketContainer packet) {
packet.getItemListModifier().modify(0, itemStacks -> {
if (itemStacks == null) {
return null;
}
itemStacks.forEach(item -> {
if (item == null)
if (item == null) {
return;
}
boolean hideEnchants = false;

View File

@@ -20,9 +20,14 @@ public class Netheric extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
if(!attacker.getWorld().getEnvironment().equals(World.Environment.NETHER))
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!attacker.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
return;
}
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -19,12 +19,17 @@ public class Nocturnal extends EcoEnchant {
@Override
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
if(!attacker.getWorld().getEnvironment().equals(World.Environment.NORMAL))
public void onMeleeAttack(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!attacker.getWorld().getEnvironment().equals(World.Environment.NORMAL)) {
return;
}
if(!(attacker.getWorld().getTime() > 12300 && attacker.getWorld().getTime() < 23850))
if (!(attacker.getWorld().getTime() > 12300 && attacker.getWorld().getTime() < 23850)) {
return;
}
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -20,7 +20,11 @@ public class Optics extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
Location land = arrow.getLocation();
Location source = attacker.getLocation();

View File

@@ -20,8 +20,13 @@ public class Oxygenate extends EcoEnchant {
@Override
public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) {
if(player.getRemainingAir() == player.getMaximumAir()) return;
public void onBlockBreak(@NotNull final Player player,
@NotNull final Block block,
final int level,
@NotNull final BlockBreakEvent event) {
if (player.getRemainingAir() == player.getMaximumAir()) {
return;
}
int oxygenLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "oxygen-per-level");
int oxygen = level * oxygenLevel;
@@ -30,4 +35,4 @@ public class Oxygenate extends EcoEnchant {
player.setRemainingAir(newOxygen);
}
}
}

View File

@@ -20,8 +20,14 @@ public class Pacify extends EcoEnchant {
@Override
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(victim instanceof Creeper)) return;
public void onTridentDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Trident trident,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(victim instanceof Creeper)) {
return;
}
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -19,8 +19,13 @@ public class Paladin extends EcoEnchant {
@Override
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(attacker.getVehicle() instanceof Horse)) return;
public void onMeleeAttack(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(attacker.getVehicle() instanceof Horse)) {
return;
}
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -22,11 +22,15 @@ public class Paralyze extends EcoEnchant {
@Override
public void onDeflect(@NotNull Player blocker, @NotNull LivingEntity attacker, int level, @NotNull EntityDamageByEntityEvent event) {
public void onDeflect(@NotNull final Player blocker,
@NotNull final LivingEntity attacker,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
if(!EnchantmentUtils.passedChance(this, level))
if (!EnchantmentUtils.passedChance(this, level)) {
return;
}
int finalDuration = duration * level;

View File

@@ -20,7 +20,11 @@ public class Parasitic extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level");
double amountToHeal = level * multiplier;
double newHealth = attacker.getHealth() + amountToHeal;

View File

@@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
public class Parry extends EcoEnchant {
public Parry() {
@@ -18,18 +19,24 @@ public class Parry extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void parryHit(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
public void parryHit(@NotNull final EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
if (event.isCancelled())
if (event.isCancelled()) {
return;
}
Player player = (Player) event.getEntity();
if (!EnchantChecks.mainhand(player, this)) return;
if (!EnchantChecks.mainhand(player, this)) {
return;
}
if (this.getDisabledWorlds().contains(player.getWorld())) return;
if (this.getDisabledWorlds().contains(player.getWorld())) {
return;
}
int level = EnchantChecks.getMainhandLevel(player, this);

View File

@@ -21,8 +21,14 @@ public class Phantasm extends EcoEnchant {
@Override
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(victim instanceof Zombie || victim instanceof Skeleton)) return;
public void onTridentDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Trident trident,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(victim instanceof Zombie || victim instanceof Skeleton)) {
return;
}
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -22,11 +22,11 @@ public class Plasmic extends EcoEnchant {
// START OF LISTENERS
private static final Material[] items;
private static final Material[] ITEMS;
static {
if(Prerequisite.MINIMUM_1_16.isMet()) {
items = new Material[]{
if (Prerequisite.MINIMUM_1_16.isMet()) {
ITEMS = new Material[]{
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
@@ -38,7 +38,7 @@ public class Plasmic extends EcoEnchant {
Material.NETHERITE_BOOTS
};
} else {
items = new Material[]{
ITEMS = new Material[]{
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
@@ -48,17 +48,28 @@ public class Plasmic extends EcoEnchant {
}
@Override
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
public void onMeleeAttack(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
EntityEquipment equipment = victim.getEquipment();
if(equipment == null) return;
if (equipment == null) {
return;
}
int pieces = 0;
for (ItemStack armorPiece : equipment.getArmorContents()) {
if(armorPiece == null) continue;
if(Arrays.asList(items).contains(armorPiece.getType())) pieces++;
if (armorPiece == null) {
continue;
}
if (Arrays.asList(ITEMS).contains(armorPiece.getType())) {
pieces++;
}
}
if(pieces == 0) return;
if (pieces == 0) {
return;
}
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -17,12 +17,21 @@ public class Protector extends EcoEnchant {
// START OF LISTENERS
@Override
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity uncastVictim, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(uncastVictim instanceof Tameable)) return;
public void onMeleeAttack(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity uncastVictim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(uncastVictim instanceof Tameable)) {
return;
}
Tameable victim = (Tameable) uncastVictim;
if(victim.getOwner() == null) return;
if(!victim.getOwner().equals(attacker)) return;
if (victim.getOwner() == null) {
return;
}
if (!victim.getOwner().equals(attacker)) {
return;
}
event.setCancelled(true);
}

View File

@@ -18,13 +18,17 @@ public class Proximity extends EcoEnchant {
@Override
public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) {
public void onMeleeAttack(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
double distance = attacker.getLocation().distance(victim.getLocation());
double decreaseAfter = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "when-closer-than-blocks");
if(distance > decreaseAfter)
if (distance > decreaseAfter) {
return;
}
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -21,9 +21,14 @@ public class Puncture extends EcoEnchant {
@Override
public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(victim instanceof Turtle || victim instanceof Shulker))
public void onTridentDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Trident trident,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(victim instanceof Turtle || victim instanceof Shulker)) {
return;
}
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -20,9 +20,14 @@ public class Quadrilateralism extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
if(!(victim instanceof Slime))
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(victim instanceof Slime)) {
return;
}
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");

View File

@@ -22,16 +22,27 @@ public class Radiance extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
double radius = level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "radius-multiplier");
int duration = level * this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level");
for (Entity e : arrow.getNearbyEntities(radius, radius, radius)) {
if(e.hasMetadata("NPC")) continue;
if (e.hasMetadata("NPC")) {
continue;
}
if (!(e instanceof LivingEntity)) continue;
if (!(e instanceof LivingEntity)) {
continue;
}
LivingEntity entity = (LivingEntity) e;
if(e.equals(attacker)) continue;
if (e.equals(attacker)) {
continue;
}
entity.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, duration, 0, false, false, false));
}

View File

@@ -25,15 +25,22 @@ public class Rage extends EcoEnchant {
@Override
public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) {
if (!EnchantmentUtils.passedChance(this, level))
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!EnchantmentUtils.passedChance(this, level)) {
return;
}
double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level");
final double distance = distancePerLevel * level;
for (Entity e : victim.getWorld().getNearbyEntities(victim.getLocation(), distance, distance, distance)) {
if (!(e instanceof Monster)) continue;
if (!(e instanceof Monster)) {
continue;
}
if (e instanceof PigZombie) {
((PigZombie) e).setAngry(true);

View File

@@ -23,9 +23,14 @@ public class Pentashot extends EcoEnchant {
@Override
public void onBowShoot(@NotNull LivingEntity shooter, @NotNull Arrow arrow, int level, @NotNull EntityShootBowEvent event) {
public void onBowShoot(@NotNull final LivingEntity shooter,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityShootBowEvent event) {
for (int i = -2; i <= 2; i += 1) {
if(i == 0) continue;
if (i == 0) {
continue;
}
Vector velocity = event.getProjectile().getVelocity();

View File

@@ -18,12 +18,16 @@ public class Preservation extends EcoEnchant {
@Override
public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) {
if(event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) return;
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageEvent event) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
return;
}
double reduction = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-less-per-level");
double multiplier = 1 - (reduction/100 * level);
double multiplier = 1 - ((reduction / 100) * level);
event.setDamage(event.getDamage() * multiplier);
}

View File

@@ -17,7 +17,9 @@ public class Quake extends Spell {
}
@Override
public void onUse(@NotNull Player player, int level, @NotNull PlayerInteractEvent event) {
public void onUse(@NotNull final Player player,
final int level,
@NotNull final PlayerInteractEvent event) {
int radius = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "radius-per-level") * level;
int damage = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level;
@@ -25,11 +27,15 @@ public class Quake extends Spell {
Collection<Entity> entities = player.getWorld().getNearbyEntities(player.getLocation(), radius, 3, radius);
for (Entity entity : entities) {
if (entity.equals(player))
if (entity.equals(player)) {
continue;
if (!(entity instanceof LivingEntity)) continue;
if (!AntigriefManager.canInjure(player, (LivingEntity) entity))
}
if (!(entity instanceof LivingEntity)) {
continue;
}
if (!AntigriefManager.canInjure(player, (LivingEntity) entity)) {
continue;
}
((LivingEntity) entity).damage(damage);
}

View File

@@ -1,7 +1,9 @@
package com.willfp.eco.core.proxy;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
@UtilityClass
public class ProxyConstants {
/**
* The NMS version that the server is running on.

View File

@@ -11,4 +11,4 @@ public interface OpenInventoryProxy extends AbstractProxy {
* @return The NMS inventory container.
*/
Object getOpenInventory(@NotNull Player player);
}
}

View File

@@ -14,7 +14,7 @@ public class Oceanic extends BiomesEnchantment {
}
@Override
public boolean isValid(@NotNull Biome biome) {
public boolean isValid(@NotNull final Biome biome) {
return Arrays.stream(new String[]{"ocean"}).anyMatch(biome.name().toLowerCase()::contains);
}
}

View File

@@ -13,7 +13,7 @@ public class Rainforest extends BiomesEnchantment {
}
@Override
public boolean isValid(@NotNull Biome biome) {
public boolean isValid(@NotNull final Biome biome) {
return Arrays.stream(new String[]{"jungle"}).anyMatch(biome.name().toLowerCase()::contains);
}
}

View File

@@ -16,6 +16,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@@ -32,21 +33,29 @@ public class Precision extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void aimingLaunch(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player))
public void aimingLaunch(@NotNull final ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player)) {
return;
}
if(!(event.getEntity() instanceof Trident))
if (!(event.getEntity() instanceof Trident)) {
return;
}
if(event.isCancelled()) return;
if (event.isCancelled()) {
return;
}
Player player = (Player) event.getEntity().getShooter();
Trident trident = (Trident) event.getEntity();
ItemStack itemStack = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident);
if (!EnchantChecks.item(itemStack, this)) return;
if(this.getDisabledWorlds().contains(player.getWorld())) return;
if (!EnchantChecks.item(itemStack, this)) {
return;
}
if (this.getDisabledWorlds().contains(player.getWorld())) {
return;
}
int level = EnchantChecks.getMainhandLevel(player, this);
@@ -54,7 +63,7 @@ public class Precision extends EcoEnchant {
final double finalDistance = level * multiplier;
Runnable runnable = this.getPlugin().getRunnableFactory().create(bukkitRunnable -> {
List<LivingEntity> nearbyEntities = (List<LivingEntity>)(List<?>) Arrays.asList(trident.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream()
List<LivingEntity> nearbyEntities = (List<LivingEntity>) (List<?>) Arrays.asList(trident.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream()
.filter(entity -> entity instanceof LivingEntity)
.filter(entity -> !entity.equals(player))
.filter(entity -> !(entity instanceof Enderman))
@@ -64,17 +73,21 @@ public class Precision extends EcoEnchant {
}
return true;
}).toArray());
if(nearbyEntities.isEmpty()) return;
if (nearbyEntities.isEmpty()) {
return;
}
LivingEntity entity = nearbyEntities.get(0);
double dist = Double.MAX_VALUE;
for(LivingEntity livingEntity : nearbyEntities) {
for (LivingEntity livingEntity : nearbyEntities) {
double currentDistance = livingEntity.getLocation().distance(trident.getLocation());
if(currentDistance >= dist) continue;
if (currentDistance >= dist) {
continue;
}
dist = currentDistance;
entity = livingEntity;
}
if(entity != null) {
if (entity != null) {
Vector vector = entity.getEyeLocation().toVector().clone().subtract(trident.getLocation().toVector()).normalize();
trident.setVelocity(vector);
}
@@ -86,8 +99,12 @@ public class Precision extends EcoEnchant {
this.getPlugin().getRunnableFactory().create(bukkitRunnable -> {
checksPerformed.addAndGet(1);
if(checksPerformed.get() > checks) bukkitRunnable.cancel();
if(trident.isDead() || trident.isInBlock() || trident.isOnGround()) bukkitRunnable.cancel();
if (checksPerformed.get() > checks) {
bukkitRunnable.cancel();
}
if (trident.isDead() || trident.isInBlock() || trident.isOnGround()) {
bukkitRunnable.cancel();
}
this.getPlugin().getScheduler().run(runnable);
}).runTaskTimer(3, period);
}

View File

@@ -1,6 +1,8 @@
package com.willfp.eco.util.integrations.placeholder;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
@@ -11,18 +13,19 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* Utility class for placeholders
*/
@UtilityClass
public class PlaceholderManager {
private static final Set<PlaceholderEntry> placeholders = new HashSet<>();
private static final Set<PlaceholderIntegration> integrations = new HashSet<>();
private static final Set<PlaceholderEntry> REGISTERED_PLACEHOLDERS = new HashSet<>();
private static final Set<PlaceholderIntegration> REGISTERED_INTEGRATIONS = new HashSet<>();
/**
* Register a new placeholder integration
*
* @param integration The {@link PlaceholderIntegration} to register
*/
public static void addIntegration(PlaceholderIntegration integration) {
public static void addIntegration(@NotNull final PlaceholderIntegration integration) {
integration.registerIntegration();
integrations.add(integration);
REGISTERED_INTEGRATIONS.add(integration);
}
/**
@@ -30,9 +33,9 @@ public class PlaceholderManager {
*
* @param expansion The {@link PlaceholderEntry} to register
*/
public static void registerPlaceholder(PlaceholderEntry expansion) {
placeholders.removeIf(placeholderEntry -> placeholderEntry.getIdentifier().equalsIgnoreCase(expansion.getIdentifier()));
placeholders.add(expansion);
public static void registerPlaceholder(@NotNull final PlaceholderEntry expansion) {
REGISTERED_PLACEHOLDERS.removeIf(placeholderEntry -> placeholderEntry.getIdentifier().equalsIgnoreCase(expansion.getIdentifier()));
REGISTERED_PLACEHOLDERS.add(expansion);
}
/**
@@ -42,13 +45,16 @@ public class PlaceholderManager {
* @param identifier The placeholder identifier
* @return The value of the placeholder
*/
public static String getResult(@Nullable Player player, String identifier) {
Optional<PlaceholderEntry> matching = placeholders.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
if (!matching.isPresent())
public static String getResult(@Nullable final Player player,
@NotNull final String identifier) {
Optional<PlaceholderEntry> matching = REGISTERED_PLACEHOLDERS.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
if (!matching.isPresent()) {
return null;
}
PlaceholderEntry entry = matching.get();
if (player == null && entry.requiresPlayer())
if (player == null && entry.requiresPlayer()) {
return "";
}
return entry.getResult(player);
}
@@ -59,9 +65,10 @@ public class PlaceholderManager {
* @param player The player to translate the placeholders with respect to
* @return The text, translated
*/
public static String translatePlaceholders(String text, @Nullable Player player) {
public static String translatePlaceholders(@NotNull final String text,
@Nullable final Player player) {
AtomicReference<String> translatedReference = new AtomicReference<>(text);
integrations.forEach(placeholderIntegration -> translatedReference.set(placeholderIntegration.translate(translatedReference.get(), player)));
REGISTERED_INTEGRATIONS.forEach(placeholderIntegration -> translatedReference.set(placeholderIntegration.translate(translatedReference.get(), player)));
return translatedReference.get();
}
}

View File

@@ -7,6 +7,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* PlaceholderAPI integration
@@ -14,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements PlaceholderIntegration {
private final AbstractEcoPlugin plugin;
public PlaceholderIntegrationPAPI(AbstractEcoPlugin plugin) {
public PlaceholderIntegrationPAPI(@NotNull final AbstractEcoPlugin plugin) {
this.plugin = plugin;
}
@@ -44,7 +45,8 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
}
@Override
public String onPlaceholderRequest(Player player, @NotNull String identifier) {
public String onPlaceholderRequest(@Nullable final Player player,
@NotNull final String identifier) {
return PlaceholderManager.getResult(player, identifier);
}
@@ -59,7 +61,8 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
}
@Override
public String translate(@NotNull String text, Player player) {
public String translate(@NotNull final String text,
@Nullable final Player player) {
return PlaceholderAPI.setPlaceholders(player, text);
}
}