#1182: Consolidate Preconditions use and minor cleanup
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.world.entity.ai.attributes.GenericAttributes;
|
||||
import net.minecraft.world.entity.animal.horse.EntityHorseAbstract;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryAbstractHorse;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
@@ -34,8 +34,7 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
|
||||
|
||||
@Override
|
||||
public void setDomestication(int value) {
|
||||
Validate.isTrue(value >= 0, "Domestication cannot be less than zero");
|
||||
Validate.isTrue(value <= getMaxDomestication(), "Domestication cannot be greater than the max domestication");
|
||||
Preconditions.checkArgument(value >= 0 && value <= this.getMaxDomestication(), "Domestication level (%s) need to be between %s and %s (max domestication)", value, 0, this.getMaxDomestication());
|
||||
getHandle().setTemper(value);
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
|
||||
|
||||
@Override
|
||||
public void setMaxDomestication(int value) {
|
||||
Validate.isTrue(value > 0, "Max domestication cannot be zero or less");
|
||||
Preconditions.checkArgument(value > 0, "Max domestication (%s) cannot be zero or less", value);
|
||||
getHandle().maxDomestication = value;
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
|
||||
|
||||
@Override
|
||||
public void setJumpStrength(double strength) {
|
||||
Validate.isTrue(strength >= 0, "Jump strength cannot be less than zero");
|
||||
Preconditions.checkArgument(strength >= 0, "Jump strength (%s) cannot be less than zero", strength);
|
||||
getHandle().getAttribute(GenericAttributes.JUMP_STRENGTH).setBaseValue(strength);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.entity.EntityAreaEffectCloud;
|
||||
import net.minecraft.world.entity.EntityLiving;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.craftbukkit.CraftParticle;
|
||||
@@ -205,7 +205,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
|
||||
@Override
|
||||
public void setBasePotionData(PotionData data) {
|
||||
Validate.notNull(data, "PotionData cannot be null");
|
||||
Preconditions.checkArgument(data != null, "PotionData cannot be null");
|
||||
getHandle().setPotionType(CraftPotionUtil.fromBukkit(data));
|
||||
}
|
||||
|
||||
@@ -222,10 +222,10 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
|
||||
|
||||
@Override
|
||||
public void setSource(ProjectileSource shooter) {
|
||||
if (shooter instanceof CraftLivingEntity) {
|
||||
getHandle().setOwner((EntityLiving) ((CraftLivingEntity) shooter).getHandle());
|
||||
if (shooter instanceof CraftLivingEntity craftLivingEntity) {
|
||||
getHandle().setOwner(craftLivingEntity.getHandle());
|
||||
} else {
|
||||
getHandle().setOwner((EntityLiving) null);
|
||||
getHandle().setOwner(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@ package org.bukkit.craftbukkit.entity;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.AbstractArrow.PickupStatus;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
@@ -20,7 +18,7 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
|
||||
|
||||
@Override
|
||||
public void setKnockbackStrength(int knockbackStrength) {
|
||||
Validate.isTrue(knockbackStrength >= 0, "Knockback cannot be negative");
|
||||
Preconditions.checkArgument(knockbackStrength >= 0, "Knockback value (%s) cannot be negative", knockbackStrength);
|
||||
getHandle().setKnockback(knockbackStrength);
|
||||
}
|
||||
|
||||
@@ -36,7 +34,7 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
|
||||
|
||||
@Override
|
||||
public void setDamage(double damage) {
|
||||
Preconditions.checkArgument(damage >= 0, "Damage must be positive");
|
||||
Preconditions.checkArgument(damage >= 0, "Damage value (%s) must be positive", damage);
|
||||
getHandle().setBaseDamage(damage);
|
||||
}
|
||||
|
||||
@@ -47,7 +45,7 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
|
||||
|
||||
@Override
|
||||
public void setPierceLevel(int pierceLevel) {
|
||||
Preconditions.checkArgument(0 <= pierceLevel && pierceLevel <= Byte.MAX_VALUE, "Pierce level out of range, expected 0 < level < 127");
|
||||
Preconditions.checkArgument(0 <= pierceLevel && pierceLevel <= Byte.MAX_VALUE, "Pierce level (%s) out of range, expected 0 < level < 127", pierceLevel);
|
||||
|
||||
getHandle().setPierceLevel((byte) pierceLevel);
|
||||
}
|
||||
@@ -99,7 +97,7 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
|
||||
|
||||
@Override
|
||||
public void setPickupStatus(PickupStatus status) {
|
||||
Preconditions.checkNotNull(status, "status");
|
||||
Preconditions.checkArgument(status != null, "PickupStatus cannot be null");
|
||||
getHandle().pickup = EntityArrow.PickupStatus.byOrdinal(status.ordinal());
|
||||
}
|
||||
|
||||
|
||||
@@ -615,7 +615,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public void setFreezeTicks(int ticks) {
|
||||
Preconditions.checkArgument(0 <= ticks, "Ticks cannot be less than 0");
|
||||
Preconditions.checkArgument(0 <= ticks, "Ticks (%s) cannot be less than 0", ticks);
|
||||
|
||||
getHandle().setTicksFrozen(ticks);
|
||||
}
|
||||
@@ -681,17 +681,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public List<org.bukkit.entity.Entity> getPassengers() {
|
||||
return Lists.newArrayList(Lists.transform(getHandle().passengers, new Function<Entity, org.bukkit.entity.Entity>() {
|
||||
@Override
|
||||
public org.bukkit.entity.Entity apply(Entity input) {
|
||||
return input.getBukkitEntity();
|
||||
}
|
||||
}));
|
||||
return Lists.newArrayList(Lists.transform(getHandle().passengers, (Function<Entity, org.bukkit.entity.Entity>) input -> input.getBukkitEntity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPassenger(org.bukkit.entity.Entity passenger) {
|
||||
Preconditions.checkArgument(passenger != null, "passenger == null");
|
||||
Preconditions.checkArgument(passenger != null, "Entity passenger cannot be null");
|
||||
Preconditions.checkArgument(!this.equals(passenger), "Entity cannot ride itself.");
|
||||
|
||||
return ((CraftEntity) passenger).getHandle().startRiding(getHandle(), true);
|
||||
@@ -699,7 +694,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public boolean removePassenger(org.bukkit.entity.Entity passenger) {
|
||||
Preconditions.checkArgument(passenger != null, "passenger == null");
|
||||
Preconditions.checkArgument(passenger != null, "Entity passenger cannot be null");
|
||||
|
||||
((CraftEntity) passenger).getHandle().stopRiding();
|
||||
return true;
|
||||
@@ -752,9 +747,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public void setTicksLived(int value) {
|
||||
if (value <= 0) {
|
||||
throw new IllegalArgumentException("Age must be at least 1 tick");
|
||||
}
|
||||
Preconditions.checkArgument(value > 0, "Age value (%s) must be positive", value);
|
||||
getHandle().tickCount = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.projectile.EntityFireball;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fireball;
|
||||
@@ -55,7 +55,7 @@ public class CraftFireball extends AbstractProjectile implements Fireball {
|
||||
|
||||
@Override
|
||||
public void setDirection(Vector direction) {
|
||||
Validate.notNull(direction, "Direction can not be null");
|
||||
Preconditions.checkArgument(direction != null, "Vector direction cannot be null");
|
||||
getHandle().setDirection(direction.getX(), direction.getY(), direction.getZ());
|
||||
update(); // SPIGOT-6579
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.entity.projectile.EntityFishingHook;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.FishHook.HookState;
|
||||
|
||||
public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
private double biteChance = -1;
|
||||
@@ -39,8 +37,8 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMinWaitTime(int minWaitTime) {
|
||||
Preconditions.checkArgument(minWaitTime >= 0 && minWaitTime <= this.getMaxWaitTime(), "The minimum wait time should be between %s and %s (the maximum wait time)", 0, this.getMaxWaitTime());
|
||||
EntityFishingHook hook = getHandle();
|
||||
Validate.isTrue(minWaitTime >= 0 && minWaitTime <= this.getMaxWaitTime(), "The minimum wait time should be between 0 and the maximum wait time.");
|
||||
hook.minWaitTime = minWaitTime;
|
||||
}
|
||||
|
||||
@@ -51,14 +49,14 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMaxWaitTime(int maxWaitTime) {
|
||||
Preconditions.checkArgument(maxWaitTime >= 0 && maxWaitTime >= this.getMinWaitTime(), "The maximum wait time should be between %s and %s (the minimum wait time)", 0, this.getMinWaitTime());
|
||||
EntityFishingHook hook = getHandle();
|
||||
Validate.isTrue(maxWaitTime >= 0 && maxWaitTime >= this.getMinWaitTime(), "The maximum wait time should be higher than or equal to 0 and the minimum wait time.");
|
||||
hook.maxWaitTime = maxWaitTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWaitTime(int min, int max) {
|
||||
Validate.isTrue(min >= 0 && max >= 0 && min <= max, "The minimum/maximum wait time should be higher than or equal to 0 and the minimum wait time.");
|
||||
Preconditions.checkArgument(min >= 0 && max >= 0 && min <= max, "The minimum/maximum wait time should be higher than or equal to 0 and the minimum wait time");
|
||||
getHandle().minWaitTime = min;
|
||||
getHandle().maxWaitTime = max;
|
||||
}
|
||||
@@ -70,7 +68,7 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMinLureTime(int minLureTime) {
|
||||
Validate.isTrue(minLureTime >= 0 && minLureTime <= this.getMaxLureTime(), "The minimum lure time should be between 0 and the maximum wait time.");
|
||||
Preconditions.checkArgument(minLureTime >= 0 && minLureTime <= this.getMaxLureTime(), "The minimum lure time (%s) should be between 0 and %s (the maximum wait time)", minLureTime, this.getMaxLureTime());
|
||||
getHandle().minLureTime = minLureTime;
|
||||
}
|
||||
|
||||
@@ -81,13 +79,13 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMaxLureTime(int maxLureTime) {
|
||||
Validate.isTrue(maxLureTime >= 0 && maxLureTime >= this.getMinLureTime(), "The maximum lure time should be higher than or equal to 0 and the minimum wait time.");
|
||||
Preconditions.checkArgument(maxLureTime >= 0 && maxLureTime >= this.getMinLureTime(), "The maximum lure time (%s) should be higher than or equal to 0 and %s (the minimum wait time)", maxLureTime, this.getMinLureTime());
|
||||
getHandle().maxLureTime = maxLureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLureTime(int min, int max) {
|
||||
Validate.isTrue(min >= 0 && max >= 0 && min <= max, "The minimum/maximum lure time should be higher than or equal to 0 and the minimum wait time.");
|
||||
Preconditions.checkArgument(min >= 0 && max >= 0 && min <= max, "The minimum/maximum lure time should be higher than or equal to 0 and the minimum wait time.");
|
||||
getHandle().minLureTime = min;
|
||||
getHandle().maxLureTime = max;
|
||||
}
|
||||
@@ -99,7 +97,7 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMinLureAngle(float minLureAngle) {
|
||||
Validate.isTrue(minLureAngle <= this.getMaxLureAngle(), "The minimum lure angle should be less than the maximum lure angle.");
|
||||
Preconditions.checkArgument(minLureAngle <= this.getMaxLureAngle(), "The minimum lure angle (%s) should be less than %s (the maximum lure angle)", minLureAngle, this.getMaxLureAngle());
|
||||
getHandle().minLureAngle = minLureAngle;
|
||||
}
|
||||
|
||||
@@ -110,13 +108,13 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setMaxLureAngle(float maxLureAngle) {
|
||||
Validate.isTrue(maxLureAngle >= this.getMinLureAngle(), "The minimum lure angle should be less than the maximum lure angle.");
|
||||
Preconditions.checkArgument(maxLureAngle >= this.getMinLureAngle(), "The minimum lure angle (%s) should be less than %s (the maximum lure angle)", maxLureAngle, this.getMinLureAngle());
|
||||
getHandle().maxLureAngle = maxLureAngle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLureAngle(float min, float max) {
|
||||
Validate.isTrue(min <= max, "The minimum lure angle should be less than the maximum lure angle.");
|
||||
Preconditions.checkArgument(min <= max, "The minimum lure (%s) angle should be less than the maximum lure angle (%s)", min, max);
|
||||
getHandle().minLureAngle = min;
|
||||
getHandle().maxLureAngle = max;
|
||||
}
|
||||
@@ -166,7 +164,7 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
||||
@Override
|
||||
public void setBiteChance(double chance) {
|
||||
Validate.isTrue(chance >= 0 && chance <= 1, "The bite chance must be between 0 and 1.");
|
||||
Preconditions.checkArgument(chance >= 0 && chance <= 1, "The bite chance must be between 0 and 1");
|
||||
this.biteChance = chance;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,8 @@ public class CraftFox extends CraftAnimals implements Fox {
|
||||
|
||||
@Override
|
||||
public void setFirstTrustedPlayer(AnimalTamer player) {
|
||||
if (player == null && getHandle().getEntityData().get(EntityFox.DATA_TRUSTED_ID_1).isPresent()) {
|
||||
throw new IllegalStateException("Must remove second trusted player first");
|
||||
if (player == null) {
|
||||
Preconditions.checkState(getHandle().getEntityData().get(EntityFox.DATA_TRUSTED_ID_1).isEmpty(), "Must remove second trusted player first");
|
||||
}
|
||||
|
||||
getHandle().getEntityData().set(EntityFox.DATA_TRUSTED_ID_0, player == null ? Optional.empty() : Optional.of(player.getUniqueId()));
|
||||
@@ -109,8 +109,8 @@ public class CraftFox extends CraftAnimals implements Fox {
|
||||
|
||||
@Override
|
||||
public void setSecondTrustedPlayer(AnimalTamer player) {
|
||||
if (player != null && !getHandle().getEntityData().get(EntityFox.DATA_TRUSTED_ID_0).isPresent()) {
|
||||
throw new IllegalStateException("Must add first trusted player first");
|
||||
if (player != null) {
|
||||
Preconditions.checkState(getHandle().getEntityData().get(EntityFox.DATA_TRUSTED_ID_0).isPresent(), "Must add first trusted player first");
|
||||
}
|
||||
|
||||
getHandle().getEntityData().set(EntityFox.DATA_TRUSTED_ID_1, player == null ? Optional.empty() : Optional.of(player.getUniqueId()));
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.animal.horse.EntityHorse;
|
||||
import net.minecraft.world.entity.animal.horse.HorseColor;
|
||||
import net.minecraft.world.entity.animal.horse.HorseStyle;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryHorse;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Horse.Color;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.Horse.Variant;
|
||||
import org.bukkit.inventory.HorseInventory;
|
||||
|
||||
public class CraftHorse extends CraftAbstractHorse implements Horse {
|
||||
@@ -36,7 +33,7 @@ public class CraftHorse extends CraftAbstractHorse implements Horse {
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
Validate.notNull(color, "Color cannot be null");
|
||||
Preconditions.checkArgument(color != null, "Color cannot be null");
|
||||
getHandle().setVariantAndMarkings(HorseColor.byId(color.ordinal()), getHandle().getMarkings());
|
||||
}
|
||||
|
||||
@@ -47,7 +44,7 @@ public class CraftHorse extends CraftAbstractHorse implements Horse {
|
||||
|
||||
@Override
|
||||
public void setStyle(Style style) {
|
||||
Validate.notNull(style, "Style cannot be null");
|
||||
Preconditions.checkArgument(style != null, "Style cannot be null");
|
||||
getHandle().setVariantAndMarkings(getHandle().getVariant(), HorseStyle.byId(style.ordinal()));
|
||||
}
|
||||
|
||||
|
||||
@@ -247,9 +247,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode mode) {
|
||||
if (mode == null) {
|
||||
throw new IllegalArgumentException("Mode cannot be null");
|
||||
}
|
||||
Preconditions.checkArgument(mode != null, "GameMode cannot be null");
|
||||
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.world.entity.decoration.EntityHanging;
|
||||
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
@@ -75,7 +74,7 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
||||
|
||||
@Override
|
||||
public void setItemDropChance(float chance) {
|
||||
Preconditions.checkArgument(0.0 <= chance && chance <= 1.0, "Chance outside range [0, 1]");
|
||||
Preconditions.checkArgument(0.0 <= chance && chance <= 1.0, "Chance (%s) outside range [0, 1]", chance);
|
||||
getHandle().dropChance = chance;
|
||||
}
|
||||
|
||||
@@ -110,7 +109,7 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
||||
|
||||
@Override
|
||||
public void setRotation(Rotation rotation) {
|
||||
Validate.notNull(rotation, "Rotation cannot be null");
|
||||
Preconditions.checkArgument(rotation != null, "Rotation cannot be null");
|
||||
getHandle().setRotation(toInteger(rotation));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ import net.minecraft.world.entity.projectile.EntityThrownExpBottle;
|
||||
import net.minecraft.world.entity.projectile.EntityThrownTrident;
|
||||
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.world.entity.projectile.EntityWitherSkull;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -113,9 +112,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
@Override
|
||||
public void setHealth(double health) {
|
||||
health = (float) health;
|
||||
if ((health < 0) || (health > getMaxHealth())) {
|
||||
throw new IllegalArgumentException("Health must be between 0 and " + getMaxHealth() + "(" + health + ")");
|
||||
}
|
||||
Preconditions.checkArgument(health >= 0 && health <= this.getMaxHealth(), "Health value (%s) must be between 0 and %s", health, this.getMaxHealth());
|
||||
|
||||
// during world generation, we don't want to run logic for dropping items and xp
|
||||
if (getHandle().generation && health == 0) {
|
||||
@@ -149,7 +146,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
|
||||
@Override
|
||||
public void setMaxHealth(double amount) {
|
||||
Validate.isTrue(amount > 0, "Max health must be greater than 0");
|
||||
Preconditions.checkArgument(amount > 0, "Max health amount (%s) must be greater than 0", amount);
|
||||
|
||||
getHandle().getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(amount);
|
||||
|
||||
@@ -486,7 +483,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
Validate.notNull(launch, "Projectile not supported");
|
||||
Preconditions.checkArgument(launch != null, "Projectile (%s) not supported", projectile.getName());
|
||||
|
||||
if (velocity != null) {
|
||||
((T) launch.getBukkitEntity()).setVelocity(velocity);
|
||||
@@ -562,9 +559,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
|
||||
@Override
|
||||
public Entity getLeashHolder() throws IllegalStateException {
|
||||
if (!isLeashed()) {
|
||||
throw new IllegalStateException("Entity not leashed");
|
||||
}
|
||||
Preconditions.checkState(isLeashed(), "Entity not leashed");
|
||||
return ((EntityInsentient) getHandle()).getLeashHolder().getBukkitEntity();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ import net.minecraft.world.level.border.IWorldBorderListener;
|
||||
import net.minecraft.world.level.saveddata.maps.MapIcon;
|
||||
import net.minecraft.world.level.saveddata.maps.WorldMap;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
@@ -242,15 +241,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void sendRawMessage(String message) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
for (IChatBaseComponent component : CraftChatMessage.fromString(message)) {
|
||||
getHandle().sendSystemMessage(component);
|
||||
}
|
||||
this.sendRawMessage(null, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawMessage(UUID sender, String message) {
|
||||
Preconditions.checkArgument(message != null, "message cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
for (IChatBaseComponent component : CraftChatMessage.fromString(message)) {
|
||||
@@ -382,6 +379,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(Location loc) {
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
// Do not directly assign here, from the packethandler we'll assign it.
|
||||
@@ -395,6 +394,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void chat(String msg) {
|
||||
Preconditions.checkArgument(msg != null, "msg cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
getHandle().connection.chat(msg, PlayerChatMessage.system(msg), false);
|
||||
@@ -402,109 +403,44 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public boolean performCommand(String command) {
|
||||
Preconditions.checkArgument(command != null, "command cannot be null");
|
||||
return server.dispatchCommand(this, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playNote(Location loc, byte instrument, byte note) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
String instrumentName = null;
|
||||
switch (instrument) {
|
||||
case 0:
|
||||
instrumentName = "harp";
|
||||
break;
|
||||
case 1:
|
||||
instrumentName = "basedrum";
|
||||
break;
|
||||
case 2:
|
||||
instrumentName = "snare";
|
||||
break;
|
||||
case 3:
|
||||
instrumentName = "hat";
|
||||
break;
|
||||
case 4:
|
||||
instrumentName = "bass";
|
||||
break;
|
||||
case 5:
|
||||
instrumentName = "flute";
|
||||
break;
|
||||
case 6:
|
||||
instrumentName = "bell";
|
||||
break;
|
||||
case 7:
|
||||
instrumentName = "guitar";
|
||||
break;
|
||||
case 8:
|
||||
instrumentName = "chime";
|
||||
break;
|
||||
case 9:
|
||||
instrumentName = "xylophone";
|
||||
break;
|
||||
}
|
||||
|
||||
float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D);
|
||||
getHandle().connection.send(new PacketPlayOutNamedSoundEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect("block.note_block." + instrumentName)), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong()));
|
||||
playNote(loc, Instrument.getByType(instrument), new Note(note));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playNote(Location loc, Instrument instrument, Note note) {
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(instrument != null, "Instrument cannot be null");
|
||||
Preconditions.checkArgument(note != null, "Note cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
String instrumentName = null;
|
||||
switch (instrument.ordinal()) {
|
||||
case 0:
|
||||
instrumentName = "harp";
|
||||
break;
|
||||
case 1:
|
||||
instrumentName = "basedrum";
|
||||
break;
|
||||
case 2:
|
||||
instrumentName = "snare";
|
||||
break;
|
||||
case 3:
|
||||
instrumentName = "hat";
|
||||
break;
|
||||
case 4:
|
||||
instrumentName = "bass";
|
||||
break;
|
||||
case 5:
|
||||
instrumentName = "flute";
|
||||
break;
|
||||
case 6:
|
||||
instrumentName = "bell";
|
||||
break;
|
||||
case 7:
|
||||
instrumentName = "guitar";
|
||||
break;
|
||||
case 8:
|
||||
instrumentName = "chime";
|
||||
break;
|
||||
case 9:
|
||||
instrumentName = "xylophone";
|
||||
break;
|
||||
case 10:
|
||||
instrumentName = "iron_xylophone";
|
||||
break;
|
||||
case 11:
|
||||
instrumentName = "cow_bell";
|
||||
break;
|
||||
case 12:
|
||||
instrumentName = "didgeridoo";
|
||||
break;
|
||||
case 13:
|
||||
instrumentName = "bit";
|
||||
break;
|
||||
case 14:
|
||||
instrumentName = "banjo";
|
||||
break;
|
||||
case 15:
|
||||
instrumentName = "pling";
|
||||
break;
|
||||
case 16:
|
||||
instrumentName = "xylophone";
|
||||
break;
|
||||
}
|
||||
String instrumentName = switch (instrument.ordinal()) {
|
||||
case 0 -> "harp";
|
||||
case 1 -> "basedrum";
|
||||
case 2 -> "snare";
|
||||
case 3 -> "hat";
|
||||
case 4 -> "bass";
|
||||
case 5 -> "flute";
|
||||
case 6 -> "bell";
|
||||
case 7 -> "guitar";
|
||||
case 8 -> "chime";
|
||||
case 9 -> "xylophone";
|
||||
case 10 -> "iron_xylophone";
|
||||
case 11 -> "cow_bell";
|
||||
case 12 -> "didgeridoo";
|
||||
case 13 -> "bit";
|
||||
case 14 -> "banjo";
|
||||
case 15 -> "pling";
|
||||
case 16 -> "xylophone";
|
||||
default -> null;
|
||||
};
|
||||
|
||||
float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
|
||||
getHandle().connection.send(new PacketPlayOutNamedSoundEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect("block.note_block." + instrumentName)), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong()));
|
||||
}
|
||||
@@ -521,17 +457,26 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (loc == null || sound == null || category == null || getHandle().connection == null) return;
|
||||
Preconditions.checkArgument(sound != null, "Sound cannot be null");
|
||||
Preconditions.checkArgument(category != null, "Category cannot be null");
|
||||
|
||||
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
getHandle().connection.send(packet);
|
||||
playSound0(loc, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (loc == null || sound == null || category == null || getHandle().connection == null) return;
|
||||
Preconditions.checkArgument(sound != null, "sound cannot be null");
|
||||
Preconditions.checkArgument(category != null, "Category cannot be null");
|
||||
|
||||
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
playSound0(loc, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
private void playSound0(Location loc, Holder<SoundEffect> soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch) {
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(soundEffectHolder, categoryNMS, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -547,17 +492,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return;
|
||||
Preconditions.checkArgument(category != null, "Category cannot be null");
|
||||
Preconditions.checkArgument(sound != null, "Sound cannot be null");
|
||||
|
||||
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
getHandle().connection.send(packet);
|
||||
playSound0(entity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(org.bukkit.entity.Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch) {
|
||||
if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return;
|
||||
Preconditions.checkArgument(category != null, "Category cannot be null");
|
||||
Preconditions.checkArgument(sound != null, "sound cannot be null");
|
||||
|
||||
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
playSound0(entity, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch);
|
||||
}
|
||||
|
||||
private void playSound0(org.bukkit.entity.Entity entity, Holder<SoundEffect> soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch) {
|
||||
Preconditions.checkArgument(entity != null, "Entity cannot be null");
|
||||
Preconditions.checkArgument(soundEffectHolder != null, "Holder of SoundEffect cannot be null");
|
||||
Preconditions.checkArgument(categoryNMS != null, "SoundCategory cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
if (!(entity instanceof CraftEntity craftEntity)) return;
|
||||
|
||||
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(soundEffectHolder, categoryNMS, craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -599,6 +556,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void playEffect(Location loc, Effect effect, int data) {
|
||||
Preconditions.checkArgument(effect != null, "Effect cannot be null");
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
int packetData = effect.getId();
|
||||
@@ -608,11 +568,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public <T> void playEffect(Location loc, Effect effect, T data) {
|
||||
Preconditions.checkArgument(effect != null, "Effect cannot be null");
|
||||
if (data != null) {
|
||||
Validate.isTrue(effect.getData() != null && effect.getData().isAssignableFrom(data.getClass()), "Wrong kind of data for this effect!");
|
||||
Preconditions.checkArgument(effect.getData() != null, "Effect.%s does not have a valid Data", effect);
|
||||
Preconditions.checkArgument(effect.getData().isAssignableFrom(data.getClass()), "%s data cannot be used for the %s effect", data.getClass().getName(), effect);
|
||||
} else {
|
||||
// Special case: the axis is optional for ELECTRIC_SPARK
|
||||
Validate.isTrue(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for this effect!");
|
||||
Preconditions.checkArgument(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for the %s effect", effect);
|
||||
}
|
||||
|
||||
int datavalue = CraftEffect.getDataValue(effect, data);
|
||||
@@ -725,19 +687,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void sendSignChange(Location loc, String[] lines, DyeColor dyeColor, boolean hasGlowingText) {
|
||||
if (getHandle().connection == null) {
|
||||
return;
|
||||
}
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
|
||||
|
||||
if (lines == null) {
|
||||
lines = new String[4];
|
||||
}
|
||||
Preconditions.checkArgument(lines.length < 4, "lines (%s) must be lower than 4", lines.length);
|
||||
|
||||
Validate.notNull(loc, "Location can not be null");
|
||||
Validate.notNull(dyeColor, "DyeColor can not be null");
|
||||
if (lines.length < 4) {
|
||||
throw new IllegalArgumentException("Must have at least 4 lines");
|
||||
}
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
|
||||
TileEntitySign sign = new TileEntitySign(CraftLocation.toBlockPosition(loc), Blocks.OAK_SIGN.defaultBlockState());
|
||||
@@ -758,8 +716,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void sendEquipmentChange(LivingEntity entity, Map<EquipmentSlot, ItemStack> items) {
|
||||
Preconditions.checkArgument(entity != null, "entity must not be null");
|
||||
Preconditions.checkArgument(items != null, "items must not be null");
|
||||
Preconditions.checkArgument(entity != null, "Entity cannot be null");
|
||||
Preconditions.checkArgument(items != null, "items cannot be null");
|
||||
|
||||
if (getHandle().connection == null) {
|
||||
return;
|
||||
@@ -1232,12 +1190,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode mode) {
|
||||
Preconditions.checkArgument(mode != null, "GameMode cannot be null");
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
if (mode == null) {
|
||||
throw new IllegalArgumentException("Mode cannot be null");
|
||||
}
|
||||
|
||||
getHandle().setGameMode(EnumGamemode.byId(mode.getValue()));
|
||||
}
|
||||
|
||||
@@ -1334,14 +1289,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void hideEntity(Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||
Validate.notNull(plugin, "Plugin cannot be null");
|
||||
Validate.isTrue(plugin.isEnabled(), "Plugin attempted to hide player while disabled");
|
||||
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
|
||||
Preconditions.checkArgument(plugin.isEnabled(), "Plugin (%s) cannot be disabled", plugin.getName());
|
||||
|
||||
hideEntity0(plugin, entity);
|
||||
}
|
||||
|
||||
private void hideEntity0(@Nullable Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||
Validate.notNull(entity, "hidden entity cannot be null");
|
||||
Preconditions.checkArgument(entity != null, "Entity hidden cannot be null");
|
||||
if (getHandle().connection == null) return;
|
||||
if (equals(entity)) return;
|
||||
|
||||
@@ -1416,14 +1371,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void showEntity(Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||
Validate.notNull(plugin, "Plugin cannot be null");
|
||||
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
|
||||
// Don't require that plugin be enabled. A plugin must be allowed to call
|
||||
// showPlayer during its onDisable() method.
|
||||
showEntity0(plugin, entity);
|
||||
}
|
||||
|
||||
private void showEntity0(@Nullable Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||
Validate.notNull(entity, "shown entity cannot be null");
|
||||
Preconditions.checkArgument(entity != null, "Entity show cannot be null");
|
||||
if (getHandle().connection == null) return;
|
||||
if (equals(entity)) return;
|
||||
|
||||
@@ -1661,10 +1616,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setResourcePack(String url, byte[] hash, String prompt, boolean force) {
|
||||
Validate.notNull(url, "Resource pack URL cannot be null");
|
||||
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
|
||||
|
||||
if (hash != null) {
|
||||
Validate.isTrue(hash.length == 20, "Resource pack hash should be 20 bytes long but was " + hash.length);
|
||||
Preconditions.checkArgument(hash.length == 20, "Resource pack hash should be 20 bytes long but was %s", hash.length);
|
||||
|
||||
getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true));
|
||||
} else {
|
||||
@@ -1759,8 +1714,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setFlying(boolean value) {
|
||||
if (!getAllowFlight() && value) {
|
||||
throw new IllegalArgumentException("Cannot make player fly if getAllowFlight() is false");
|
||||
if (!getAllowFlight()) {
|
||||
Preconditions.checkArgument(!value, "Player is not allowed to fly (check #getAllowFlight())");
|
||||
}
|
||||
|
||||
getHandle().getAbilities().flying = value;
|
||||
@@ -1826,21 +1781,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
|
||||
private void validateSpeed(float value) {
|
||||
if (value < 0) {
|
||||
if (value < -1f) {
|
||||
throw new IllegalArgumentException(value + " is too low");
|
||||
}
|
||||
} else {
|
||||
if (value > 1f) {
|
||||
throw new IllegalArgumentException(value + " is too high");
|
||||
}
|
||||
}
|
||||
Preconditions.checkArgument(value <= 1f && value >= -1f, "Speed value (%s) need to be between -1f and 1f", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxHealth(double amount) {
|
||||
super.setMaxHealth(amount);
|
||||
this.health = Math.min(this.health, health);
|
||||
this.health = Math.min(this.health, amount);
|
||||
getHandle().resetSentInfo();
|
||||
}
|
||||
|
||||
@@ -1857,21 +1804,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setScoreboard(Scoreboard scoreboard) {
|
||||
Validate.notNull(scoreboard, "Scoreboard cannot be null");
|
||||
PlayerConnection playerConnection = getHandle().connection;
|
||||
if (playerConnection == null) {
|
||||
throw new IllegalStateException("Cannot set scoreboard yet");
|
||||
}
|
||||
if (playerConnection.isDisconnected()) {
|
||||
throw new IllegalStateException("Cannot set scoreboard for invalid CraftPlayer");
|
||||
}
|
||||
Preconditions.checkArgument(scoreboard != null, "Scoreboard cannot be null");
|
||||
Preconditions.checkState(getHandle().connection != null, "Cannot set scoreboard yet (invalid player connection)");
|
||||
Preconditions.checkState(getHandle().connection.isDisconnected(), "Cannot set scoreboard for invalid CraftPlayer (player is disconnected)");
|
||||
|
||||
this.server.getScoreboardManager().setPlayerBoard(this, scoreboard);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealthScale(double value) {
|
||||
Validate.isTrue((float) value > 0F, "Must be greater than 0");
|
||||
Preconditions.checkArgument(value > 0F, "Health value (%s) must be greater than 0", value);
|
||||
healthScale = value;
|
||||
scaledHealth = true;
|
||||
updateScaledHealth();
|
||||
@@ -2044,8 +1986,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
|
||||
if (data != null && !particle.getDataType().isInstance(data)) {
|
||||
throw new IllegalArgumentException("data should be " + particle.getDataType() + " got " + data.getClass());
|
||||
if (data != null) {
|
||||
Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType());
|
||||
}
|
||||
PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(CraftParticle.toNMS(particle, data), true, (float) x, (float) y, (float) z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) extra, count);
|
||||
getHandle().connection.send(packetplayoutworldparticles);
|
||||
@@ -2087,8 +2029,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void openBook(ItemStack book) {
|
||||
Validate.isTrue(book != null, "book == null");
|
||||
Validate.isTrue(book.getType() == Material.WRITTEN_BOOK, "Book must be Material.WRITTEN_BOOK");
|
||||
Preconditions.checkArgument(book != null, "ItemStack cannot be null");
|
||||
Preconditions.checkArgument(book.getType() == Material.WRITTEN_BOOK, "ItemStack Material (%s) must be Material.WRITTEN_BOOK", book.getType());
|
||||
|
||||
ItemStack hand = getInventory().getItemInMainHand();
|
||||
getInventory().setItemInMainHand(book);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Collection;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.projectile.EntityPotion;
|
||||
import net.minecraft.world.item.alchemy.PotionUtil;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
@@ -36,11 +36,8 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw
|
||||
|
||||
@Override
|
||||
public void setItem(ItemStack item) {
|
||||
// The ItemStack must not be null.
|
||||
Validate.notNull(item, "ItemStack cannot be null.");
|
||||
|
||||
// The ItemStack must be a potion.
|
||||
Validate.isTrue(item.getType() == Material.LINGERING_POTION || item.getType() == Material.SPLASH_POTION, "ItemStack must be a lingering or splash potion. This item stack was " + item.getType() + ".");
|
||||
Preconditions.checkArgument(item != null, "ItemStack cannot be null");
|
||||
Preconditions.checkArgument(item.getType() == Material.LINGERING_POTION || item.getType() == Material.SPLASH_POTION, "ItemStack material must be Material.LINGERING_POTION or Material.SPLASH_POTION but was Material.%s", item.getType());
|
||||
|
||||
getHandle().setItem(CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
@@ -105,7 +105,7 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
|
||||
|
||||
@Override
|
||||
public void setBasePotionData(PotionData data) {
|
||||
Validate.notNull(data, "PotionData cannot be null");
|
||||
Preconditions.checkArgument(data != null, "PotionData cannot be null");
|
||||
getHandle().setPotionType(CraftPotionUtil.fromBukkit(data));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import net.minecraft.world.entity.npc.EntityVillager;
|
||||
import net.minecraft.world.entity.npc.VillagerProfession;
|
||||
import net.minecraft.world.level.block.BlockBed;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
@@ -55,7 +54,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@Override
|
||||
public void setProfession(Profession profession) {
|
||||
Validate.notNull(profession);
|
||||
Preconditions.checkArgument(profession != null, "Profession cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(profession)));
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@Override
|
||||
public void setVillagerType(Type type) {
|
||||
Validate.notNull(type);
|
||||
Preconditions.checkArgument(type != null, "Type cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))));
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@Override
|
||||
public void setVillagerLevel(int level) {
|
||||
Preconditions.checkArgument(1 <= level && level <= 5, "level must be between [1, 5]");
|
||||
Preconditions.checkArgument(1 <= level && level <= 5, "level (%s) must be between [1, 5]", level);
|
||||
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setLevel(level));
|
||||
}
|
||||
@@ -89,7 +88,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
|
||||
@Override
|
||||
public void setVillagerExperience(int experience) {
|
||||
Preconditions.checkArgument(experience >= 0, "Experience must be positive");
|
||||
Preconditions.checkArgument(experience >= 0, "Experience (%s) must be positive", experience);
|
||||
|
||||
getHandle().setVillagerXp(experience);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.monster.EntityZombieVillager;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
@@ -44,7 +42,7 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager {
|
||||
|
||||
@Override
|
||||
public void setVillagerProfession(Villager.Profession profession) {
|
||||
Validate.notNull(profession);
|
||||
Preconditions.checkArgument(profession != null, "Villager.Profession cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setProfession(BuiltInRegistries.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT)))));
|
||||
}
|
||||
|
||||
@@ -55,7 +53,7 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager {
|
||||
|
||||
@Override
|
||||
public void setVillagerType(Villager.Type type) {
|
||||
Validate.notNull(type);
|
||||
Preconditions.checkArgument(type != null, "Villager.Type cannot be null");
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))));
|
||||
}
|
||||
|
||||
@@ -79,7 +77,7 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager {
|
||||
getHandle().conversionStarter = null;
|
||||
getHandle().removeEffect(MobEffects.DAMAGE_BOOST, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION);
|
||||
} else {
|
||||
getHandle().startConverting((UUID) null, time);
|
||||
getHandle().startConverting(null, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user