Style cleanup

This commit is contained in:
TheMode 2021-08-15 17:50:38 +02:00
parent d53d2ecea5
commit b6ab689b10
2 changed files with 17 additions and 29 deletions

View File

@ -447,8 +447,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* @return an unmodifiable {@link Set} containing all the players in the instance * @return an unmodifiable {@link Set} containing all the players in the instance
*/ */
@Override @Override
@NotNull public @NotNull Set<@NotNull Player> getPlayers() {
public Set<Player> getPlayers() {
return Collections.unmodifiableSet(players); return Collections.unmodifiableSet(players);
} }
@ -457,8 +456,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @return an unmodifiable {@link Set} containing all the creatures in the instance * @return an unmodifiable {@link Set} containing all the creatures in the instance
*/ */
@NotNull public @NotNull Set<@NotNull EntityCreature> getCreatures() {
public Set<EntityCreature> getCreatures() {
return Collections.unmodifiableSet(creatures); return Collections.unmodifiableSet(creatures);
} }
@ -467,8 +465,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @return an unmodifiable {@link Set} containing all the experience orbs in the instance * @return an unmodifiable {@link Set} containing all the experience orbs in the instance
*/ */
@NotNull public @NotNull Set<@NotNull ExperienceOrb> getExperienceOrbs() {
public Set<ExperienceOrb> getExperienceOrbs() {
return Collections.unmodifiableSet(experienceOrbs); return Collections.unmodifiableSet(experienceOrbs);
} }
@ -479,7 +476,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* @return an unmodifiable {@link Set} containing all the entities in a chunk, * @return an unmodifiable {@link Set} containing all the entities in a chunk,
* if {@code chunk} is unloaded, return an empty {@link HashSet} * if {@code chunk} is unloaded, return an empty {@link HashSet}
*/ */
public @NotNull Set<Entity> getChunkEntities(Chunk chunk) { public @NotNull Set<@NotNull Entity> getChunkEntities(Chunk chunk) {
if (!ChunkUtils.isLoaded(chunk)) if (!ChunkUtils.isLoaded(chunk))
return Collections.emptySet(); return Collections.emptySet();
final Set<Entity> entities; final Set<Entity> entities;
@ -587,7 +584,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
// Load the chunk if not already (or throw an error if auto chunk load is disabled) // Load the chunk if not already (or throw an error if auto chunk load is disabled)
loadOptionalChunk(entityPosition).thenAccept(chunk -> { loadOptionalChunk(entityPosition).thenAccept(chunk -> {
Check.notNull(chunk, "You tried to spawn an entity in an unloaded chunk, " + entityPosition); Check.notNull(chunk, "You tried to spawn an entity in an unloaded chunk, {0}", entityPosition);
UNSAFE_addEntityToChunk(entity, chunk); UNSAFE_addEntityToChunk(entity, chunk);
}); });
}); });
@ -602,10 +599,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
*/ */
@ApiStatus.Internal @ApiStatus.Internal
public void UNSAFE_removeEntity(@NotNull Entity entity) { public void UNSAFE_removeEntity(@NotNull Entity entity) {
final Instance entityInstance = entity.getInstance(); if (entity.getInstance() != this) return;
if (entityInstance != this)
return;
RemoveEntityFromInstanceEvent event = new RemoveEntityFromInstanceEvent(this, entity); RemoveEntityFromInstanceEvent event = new RemoveEntityFromInstanceEvent(this, entity);
EventDispatcher.callCancellable(event, () -> { EventDispatcher.callCancellable(event, () -> {
// Remove this entity from players viewable list and send delete entities packet // Remove this entity from players viewable list and send delete entities packet
@ -697,31 +691,24 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
callback.accept(this); callback.accept(this);
} }
} }
// Time // Time
{ {
this.worldAge++; this.worldAge++;
this.time += timeRate; this.time += timeRate;
// time needs to be sent to players
// time needs to be send to players
if (timeUpdate != null && !Cooldown.hasCooldown(time, lastTimeUpdate, timeUpdate)) { if (timeUpdate != null && !Cooldown.hasCooldown(time, lastTimeUpdate, timeUpdate)) {
PacketUtils.sendGroupedPacket(getPlayers(), createTimePacket()); PacketUtils.sendGroupedPacket(getPlayers(), createTimePacket());
this.lastTimeUpdate = time; this.lastTimeUpdate = time;
} }
} }
// Tick event // Tick event
{ {
// Process tick events // Process tick events
InstanceTickEvent chunkTickEvent = new InstanceTickEvent(this, time, lastTickAge); EventDispatcher.call(new InstanceTickEvent(this, time, lastTickAge));
EventDispatcher.call(chunkTickEvent);
// Set last tick age // Set last tick age
lastTickAge = time; this.lastTickAge = time;
} }
this.worldBorder.update(); this.worldBorder.update();
} }
@ -776,8 +763,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @return the instance explosion supplier, null if none was provided * @return the instance explosion supplier, null if none was provided
*/ */
@Nullable public @Nullable ExplosionSupplier getExplosionSupplier() {
public ExplosionSupplier getExplosionSupplier() {
return explosionSupplier; return explosionSupplier;
} }
@ -797,8 +783,8 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @return the instance space * @return the instance space
*/ */
@NotNull @ApiStatus.Internal
public PFInstanceSpace getInstanceSpace() { public @NotNull PFInstanceSpace getInstanceSpace() {
return instanceSpace; return instanceSpace;
} }

View File

@ -82,7 +82,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public synchronized void setBlock(int x, int y, int z, @NotNull Block block) { public void setBlock(int x, int y, int z, @NotNull Block block) {
final Chunk chunk = getChunkAt(x, z); final Chunk chunk = getChunkAt(x, z);
if (ChunkUtils.isLoaded(chunk)) { if (ChunkUtils.isLoaded(chunk)) {
UNSAFE_setBlock(chunk, x, y, z, block, null, null); UNSAFE_setBlock(chunk, x, y, z, block, null, null);
@ -106,8 +106,8 @@ public class InstanceContainer extends Instance {
* @param z the block Z * @param z the block Z
* @param block the block to place * @param block the block to place
*/ */
private void UNSAFE_setBlock(@NotNull Chunk chunk, int x, int y, int z, @NotNull Block block, private synchronized void UNSAFE_setBlock(@NotNull Chunk chunk, int x, int y, int z, @NotNull Block block,
@Nullable BlockHandler.Placement placement, @Nullable BlockHandler.Destroy destroy) { @Nullable BlockHandler.Placement placement, @Nullable BlockHandler.Destroy destroy) {
if (chunk.isReadOnly()) return; if (chunk.isReadOnly()) return;
synchronized (chunk) { synchronized (chunk) {
// Refresh the last block change time // Refresh the last block change time
@ -261,7 +261,9 @@ public class InstanceContainer extends Instance {
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>(); CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
final IChunkLoader loader = chunkLoader; final IChunkLoader loader = chunkLoader;
final Runnable retriever = () -> loader.loadChunk(this, chunkX, chunkZ) final Runnable retriever = () -> loader.loadChunk(this, chunkX, chunkZ)
// create the chunk from scratch (with the generator) if the loader couldn't
.thenCompose(chunk -> chunk != null ? CompletableFuture.completedFuture(chunk) : createChunk(chunkX, chunkZ)) .thenCompose(chunk -> chunk != null ? CompletableFuture.completedFuture(chunk) : createChunk(chunkX, chunkZ))
// cache the retrieved chunk (in the next instance tick for thread-safety)
.whenComplete((chunk, throwable) -> scheduleNextTick(instance -> { .whenComplete((chunk, throwable) -> scheduleNextTick(instance -> {
cacheChunk(chunk); cacheChunk(chunk);
EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ)); EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ));