Fix most checkstyle warnings

This commit is contained in:
ThatCreeper 2020-12-30 19:27:29 -06:00
parent c3d6af3afe
commit 0ce094567b
2 changed files with 58 additions and 6 deletions

View File

@ -404,7 +404,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
// remove expired effects
{
effects.removeIf(timedPotion -> time >=
effects.removeIf(timedPotion -> time
>=
(timedPotion.getStartingTime() + timedPotion.getPotion().getDuration() * MinecraftServer.TICK_MS));
}
@ -1474,7 +1475,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
}
/**
* Adds an effect to an entity
* Adds an effect to an entity.
*
* @param potion The potion to add
*/

View File

@ -1,7 +1,6 @@
package net.minestom.server.potion;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.EntityEffectPacket;
import net.minestom.server.network.packet.server.play.RemoveEntityEffectPacket;
import org.jetbrains.annotations.NotNull;
@ -12,26 +11,66 @@ public class Potion {
private final int duration;
private final byte flags;
/**
* Creates a new potion.
*
* @param effect The type of potion.
* @param amplifier The strength of the potion.
* @param duration The length of the potion in ticks.
*/
public Potion(PotionEffect effect, byte amplifier, int duration) {
this(effect, amplifier, duration, true, true, false);
}
/**
* Creates a new potion.
*
* @param effect The type of potion.
* @param amplifier The strength of the potion.
* @param duration The length of the potion in ticks.
* @param particles If the potion has particles.
*/
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles) {
this(effect, amplifier, duration, particles, true, false);
}
/**
* Creates a new potion.
*
* @param effect The type of potion.
* @param amplifier The strength of the potion.
* @param duration The length of the potion in ticks.
* @param particles If the potion has particles.
* @param icon If the potion has an icon.
*/
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon) {
this(effect, amplifier, duration, particles, icon, false);
}
/**
* Creates a new potion.
*
* @param effect The type of potion.
* @param amplifier The strength of the potion.
* @param duration The length of the potion in ticks.
* @param particles If the potion has particles.
* @param icon If the potion has an icon.
* @param ambient If the potion came from a beacon.
*/
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon, boolean ambient) {
this.effect = effect;
this.amplifier = amplifier;
this.duration = duration;
byte flags = 0;
if (ambient) flags = (byte)(flags | 0x01);
if (particles) flags = (byte)(flags | 0x02);
if (icon) flags = (byte)(flags | 0x04);
if (ambient) {
flags = (byte) (flags | 0x01);
}
if (particles) {
flags = (byte) (flags | 0x02);
}
if (icon) {
flags = (byte) (flags | 0x04);
}
this.flags = flags;
}
@ -51,6 +90,12 @@ public class Potion {
return flags;
}
/**
* Sends a packet that a potion effect has been applied to the entity.
* <p>
* Used internally by {@link net.minestom.server.entity.Player#addEffect(Potion)}
* @param entity
*/
public void sendAddPacket(@NotNull Entity entity) {
EntityEffectPacket eep = new EntityEffectPacket();
eep.entityId = entity.getEntityId();
@ -58,6 +103,12 @@ public class Potion {
entity.sendPacketToViewersAndSelf(eep);
}
/**
* Sends a packet that a potion effect has been removed from the entity.
* <p>
* Used internally by {@link net.minestom.server.entity.Player#removeEffect(PotionEffect)}
* @param entity
*/
public void sendRemovePacket(@NotNull Entity entity) {
RemoveEntityEffectPacket reep = new RemoveEntityEffectPacket();
reep.entityId = entity.getEntityId();