mirror of
https://github.com/PaperMC/Paper.git
synced 2025-11-18 20:54:27 +01:00
fixup previous commits
This commit is contained in:
parent
05145d0981
commit
a6b5dcb222
@ -1,14 +1,16 @@
|
||||
package io.papermc.paper.event.world.border;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.util.Tick;
|
||||
import java.time.Duration;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Called when a world border changes its bounds, either over time, or instantly.
|
||||
@ -66,7 +68,7 @@ public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Ca
|
||||
* @param newSize the new size
|
||||
*/
|
||||
public void setNewSize(final double newSize) {
|
||||
this.newSize = Math.min(this.worldBorder.getMaxSize(), Math.max(1.0D, newSize));
|
||||
this.newSize = Math.clamp(newSize, 1.0D, this.worldBorder.getMaxSize());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,10 +76,24 @@ public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Ca
|
||||
*
|
||||
* @return the time in ticks for the change
|
||||
*/
|
||||
public long getDurationTicks() {
|
||||
public @Range(from = 0, to = Integer.MAX_VALUE) long getDurationTicks() {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time in ticks for the change. Will change {@link #getType()} to return
|
||||
* {@link Type#STARTED_MOVE}.
|
||||
*
|
||||
* @param duration the time in ticks for the change
|
||||
*/
|
||||
public void setDurationTicks(final @Range(from = 0, to = Integer.MAX_VALUE) long duration) {
|
||||
Preconditions.checkArgument(duration >= 0 && duration <= Integer.MAX_VALUE, "duration must be between 0-%s", Integer.MAX_VALUE);
|
||||
this.duration = duration;
|
||||
if (this.type == Type.INSTANT_MOVE) {
|
||||
this.type = Type.STARTED_MOVE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time in milliseconds for the change. Will be 0 if instant.
|
||||
*
|
||||
@ -85,21 +101,8 @@ public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Ca
|
||||
* @deprecated in favor of {@link #getDurationTicks()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.11")
|
||||
public long getDuration() {
|
||||
return Tick.of(this.duration).toMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time in ticks for the change. Will change {@link #getType()} to return
|
||||
* {@link Type#STARTED_MOVE}.
|
||||
*
|
||||
* @param duration the time in ticks for the change
|
||||
*/
|
||||
public void setDurationTicks(@Range(from = 0, to = Integer.MAX_VALUE) final long duration) {
|
||||
this.duration = Math.clamp(duration, 0L, Integer.MAX_VALUE);
|
||||
if (this.type == Type.INSTANT_MOVE) {
|
||||
this.type = Type.STARTED_MOVE;
|
||||
}
|
||||
public @NonNegative long getDuration() {
|
||||
return Tick.of(this.getDurationTicks()).toMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,8 +113,8 @@ public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Ca
|
||||
* @deprecated in favor of {@link #setDurationTicks(long)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.11")
|
||||
public void setDuration(final long duration) {
|
||||
this.setDurationTicks(Tick.tick().fromDuration(Duration.ofMillis(Math.clamp(duration, 0L, Integer.MAX_VALUE))));
|
||||
public void setDuration(final @NonNegative long duration) {
|
||||
this.setDurationTicks(Tick.tick().fromDuration(Duration.ofMillis(duration)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package org.bukkit;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.util.Tick;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public interface WorldBorder {
|
||||
|
||||
@ -35,24 +37,10 @@ public interface WorldBorder {
|
||||
* @param newSize The new size of the border.
|
||||
*
|
||||
* @throws IllegalArgumentException if newSize is less than 1.0D or greater than {@link #getMaxSize()}
|
||||
* @see #changeSize(double, long)
|
||||
*/
|
||||
void setSize(double newSize);
|
||||
|
||||
/**
|
||||
* Sets the border to a square region with the specified side length in blocks.
|
||||
*
|
||||
* @param newSize The new side length of the border.
|
||||
* @param seconds The time in seconds in which the border grows or shrinks from the previous size to that being set.
|
||||
*
|
||||
* @throws IllegalArgumentException if newSize is less than 1.0D or greater than {@link #getMaxSize()}
|
||||
* @see #setSize(double, TimeUnit, long)
|
||||
* @deprecated Use {@link #changeSize(double, long)} instead
|
||||
*/
|
||||
@Deprecated(since = "1.21.11", forRemoval = true)
|
||||
default void setSize(double newSize, long seconds) {
|
||||
this.setSize(Math.min(this.getMaxSize(), Math.max(1.0D, newSize)), TimeUnit.SECONDS, Math.clamp(seconds, 0L, Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the border to a square region with the specified side length in blocks.
|
||||
*
|
||||
@ -60,9 +48,24 @@ public interface WorldBorder {
|
||||
* @param ticks The time in ticks in which the border grows or shrinks from the previous size to that being set.
|
||||
*
|
||||
* @throws IllegalArgumentException if newSize is less than 1.0D or greater than {@link #getMaxSize()}
|
||||
* @throws IllegalArgumentException if ticks are less than 0
|
||||
* @throws IllegalArgumentException if ticks is out of range
|
||||
* @see #setSize(double)
|
||||
*/
|
||||
void changeSize(double newSize, long ticks);
|
||||
void changeSize(double newSize, @Range(from = 0, to = Integer.MAX_VALUE) long ticks);
|
||||
|
||||
/**
|
||||
* Sets the border to a square region with the specified side length in blocks.
|
||||
*
|
||||
* @param newSize The new side length of the border.
|
||||
* @param seconds The time in seconds in which the border grows or shrinks from the previous size to that being set.
|
||||
*
|
||||
* @throws IllegalArgumentException if seconds is out of range once converted in ticks
|
||||
* @deprecated Use {@link #changeSize(double, long)} instead
|
||||
*/
|
||||
@Deprecated(since = "1.21.11", forRemoval = true)
|
||||
default void setSize(double newSize, long seconds) {
|
||||
this.changeSize(Math.clamp(newSize, 1.0D, this.getMaxSize()), Tick.tick().fromDuration(Duration.ofSeconds(seconds)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the border to a square region with the specified side length in blocks.
|
||||
@ -71,13 +74,12 @@ public interface WorldBorder {
|
||||
* @param unit The time unit.
|
||||
* @param time The time in which the border grows or shrinks from the previous size to that being set.
|
||||
*
|
||||
* @throws IllegalArgumentException if unit is <code>null</code> or newSize is less than 1.0D or greater than {@link #getMaxSize()}
|
||||
*
|
||||
* @see Tick
|
||||
* @throws IllegalArgumentException if newSize is less than 1.0D or greater than {@link #getMaxSize()}
|
||||
* @throws IllegalArgumentException if time is out of range once converted in ticks
|
||||
* @deprecated Use {@link #changeSize(double, long)} instead
|
||||
*/
|
||||
@Deprecated(since = "1.21.11", forRemoval = true)
|
||||
default void setSize(double newSize, @NotNull TimeUnit unit, long time) {
|
||||
default void setSize(double newSize, @NotNull TimeUnit unit, @NonNegative long time) {
|
||||
Preconditions.checkArgument(unit != null, "TimeUnit cannot be null.");
|
||||
this.changeSize(newSize, Tick.tick().fromDuration(Duration.of(time, unit.toChronoUnit())));
|
||||
}
|
||||
@ -143,17 +145,10 @@ public interface WorldBorder {
|
||||
* @deprecated Use {@link #getWarningTimeTicks()} instead
|
||||
*/
|
||||
@Deprecated(since = "1.21.11", forRemoval = true)
|
||||
default int getWarningTime() {
|
||||
default @NonNegative int getWarningTime() {
|
||||
return (int) Tick.of(this.getWarningTimeTicks()).toSeconds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current border warning time in ticks.
|
||||
*
|
||||
* @return The current border warning time in ticks.
|
||||
*/
|
||||
int getWarningTimeTicks();
|
||||
|
||||
/**
|
||||
* Sets the warning time that causes the screen to be tinted red when a contracting border will reach the player within the specified time.
|
||||
*
|
||||
@ -161,16 +156,25 @@ public interface WorldBorder {
|
||||
* @deprecated Use {@link #setWarningTimeTicks(int)} instead
|
||||
*/
|
||||
@Deprecated(since = "1.21.11", forRemoval = true)
|
||||
default void setWarningTime(int seconds) {
|
||||
default void setWarningTime(@NonNegative int seconds) {
|
||||
Preconditions.checkArgument(seconds >= 0, "seconds cannot be lower than 0");
|
||||
|
||||
this.setWarningTimeTicks(Tick.tick().fromDuration(Duration.ofSeconds(seconds)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current border warning time in ticks.
|
||||
*
|
||||
* @return The current border warning time in ticks.
|
||||
*/
|
||||
@NonNegative int getWarningTimeTicks();
|
||||
|
||||
/**
|
||||
* Sets the warning time that causes the screen to be tinted red when a contracting border will reach the player within the specified time.
|
||||
*
|
||||
* @param ticks The number of ticks.
|
||||
*/
|
||||
void setWarningTimeTicks(int ticks);
|
||||
void setWarningTimeTicks(@NonNegative int ticks);
|
||||
|
||||
/**
|
||||
* Gets the current border warning distance.
|
||||
|
||||
@ -49,7 +49,6 @@ import org.bukkit.Art;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.GameRules;
|
||||
import org.bukkit.JukeboxSong;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@ -1416,7 +1416,9 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
public WorldBorder createWorldBorder() {
|
||||
return new CraftWorldBorder(new net.minecraft.world.level.border.WorldBorder());
|
||||
net.minecraft.world.level.border.WorldBorder border = new net.minecraft.world.level.border.WorldBorder();
|
||||
border.setWarningTime(net.minecraft.world.level.border.WorldBorder.Settings.DEFAULT.warningTime()); // TODO remove once MC-304061 is truly fixed
|
||||
return new CraftWorldBorder(border);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,7 +6,6 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.JavaOps;
|
||||
import io.papermc.paper.FeatureHooks;
|
||||
import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder;
|
||||
import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl;
|
||||
@ -58,6 +57,7 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.NullOps;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributes;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
@ -1742,7 +1742,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
if (rule instanceof CraftGameRule.LegacyGameRuleWrapper legacyGameRuleWrapper) {
|
||||
convertedValue = (T) legacyGameRuleWrapper.getFromLegacyToModern().apply(newValue);
|
||||
} else {
|
||||
nms.valueCodec().encodeStart(JavaOps.INSTANCE, newValue).ifError(error -> {
|
||||
nms.valueCodec().encodeStart(NullOps.INSTANCE, newValue).ifError(error -> {
|
||||
throw CraftGameRule.INVALID_VALUE.apply(newValue.toString(), error);
|
||||
});
|
||||
convertedValue = newValue;
|
||||
|
||||
@ -38,12 +38,12 @@ public class CraftWorldBorder implements WorldBorder {
|
||||
|
||||
@Override
|
||||
public void setSize(double newSize) {
|
||||
this.changeSize(newSize, 0);
|
||||
this.handle.setSize(newSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeSize(double newSize, long ticks) {
|
||||
Preconditions.checkArgument(ticks >= 0, "ticks cannot be lower than 0");
|
||||
Preconditions.checkArgument(ticks >= 0 && ticks <= Integer.MAX_VALUE, "ticks must be between 0-%s", Integer.MAX_VALUE);
|
||||
Preconditions.checkArgument(newSize >= 1.0D && newSize <= this.getMaxSize(), "newSize must be between 1.0D and %s", this.getMaxSize());
|
||||
|
||||
if (ticks > 0L) {
|
||||
|
||||
@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.animal.nautilus.AbstractNautilus;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftSaddledInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryHorse;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftAbstractNautilus extends CraftTameableAnimal implements org.bukkit.entity.AbstractNautilus {
|
||||
@ -18,8 +18,8 @@ public class CraftAbstractNautilus extends CraftTameableAnimal implements org.bu
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return new CraftSaddledInventory(
|
||||
getHandle().inventory,
|
||||
return new CraftInventoryHorse(
|
||||
this.getHandle().inventory,
|
||||
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY),
|
||||
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.SADDLE)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user