mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-19 06:32:03 +01:00
Code cleanup
This commit is contained in:
parent
50373505b3
commit
0da78193c5
@ -36,7 +36,6 @@ public class MinecraftServer {
|
||||
public static final String THREAD_NAME_BENCHMARK = "Ms-Benchmark";
|
||||
|
||||
public static final String THREAD_NAME_MAIN_UPDATE = "Ms-MainUpdate";
|
||||
public static final int THREAD_COUNT_MAIN_UPDATE = 1; // Keep it to 1
|
||||
|
||||
public static final String THREAD_NAME_PACKET_WRITER = "Ms-PacketWriterPool";
|
||||
public static final int THREAD_COUNT_PACKET_WRITER = 2;
|
||||
|
@ -12,14 +12,19 @@ import net.minestom.server.utils.thread.MinestomThread;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class UpdateManager {
|
||||
public final class UpdateManager {
|
||||
|
||||
private static final long KEEP_ALIVE_DELAY = 10_000;
|
||||
private static final long KEEP_ALIVE_KICK = 30_000;
|
||||
|
||||
private ExecutorService mainUpdate = new MinestomThread(MinecraftServer.THREAD_COUNT_MAIN_UPDATE, MinecraftServer.THREAD_NAME_MAIN_UPDATE);
|
||||
private ExecutorService mainUpdate = new MinestomThread(1, MinecraftServer.THREAD_NAME_MAIN_UPDATE);
|
||||
private boolean stopRequested;
|
||||
|
||||
/**
|
||||
* Should only be created in MinecraftServer
|
||||
*/
|
||||
protected UpdateManager() {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
mainUpdate.execute(() -> {
|
||||
|
@ -12,6 +12,9 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* Represent a bossbar which can be showed to any player {@link #addViewer(Player)}
|
||||
*/
|
||||
public class BossBar implements Viewable {
|
||||
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
@ -51,6 +54,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bossbar title
|
||||
*
|
||||
* @return the current title of the bossbar
|
||||
*/
|
||||
public String getTitle() {
|
||||
@ -58,6 +63,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bossbar title
|
||||
*
|
||||
* @param title the new title of the bossbar
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
@ -65,6 +72,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bossbar progress
|
||||
*
|
||||
* @return the current progress of the bossbar
|
||||
*/
|
||||
public float getProgress() {
|
||||
@ -72,6 +81,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bossbar progress
|
||||
*
|
||||
* @param progress the new progress bar percentage
|
||||
* @throws IllegalArgumentException if {@code progress} is not between 0 and 1
|
||||
*/
|
||||
@ -83,6 +94,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bossbar color
|
||||
*
|
||||
* @return the current bossbar color
|
||||
*/
|
||||
public BarColor getColor() {
|
||||
@ -90,6 +103,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bossbar color
|
||||
*
|
||||
* @param color the new color of the bossbar
|
||||
*/
|
||||
public void setColor(BarColor color) {
|
||||
@ -98,6 +113,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bossbar division
|
||||
*
|
||||
* @return the current bossbar division
|
||||
*/
|
||||
public BarDivision getDivision() {
|
||||
@ -105,6 +122,8 @@ public class BossBar implements Viewable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bossbar division
|
||||
*
|
||||
* @param division the new bossbar division count
|
||||
*/
|
||||
public void setDivision(BarDivision division) {
|
||||
|
@ -12,7 +12,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataManager {
|
||||
public final class DataManager {
|
||||
|
||||
private Map<Class, DataType> dataTypeMap = new HashMap<>();
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class EntityManager {
|
||||
public final class EntityManager {
|
||||
|
||||
private static InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
||||
|
||||
|
@ -31,7 +31,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
// TODO light data & API
|
||||
public class Chunk implements Viewable {
|
||||
public final class Chunk implements Viewable {
|
||||
|
||||
private static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
|
||||
|
||||
@ -230,19 +230,19 @@ public class Chunk implements Viewable {
|
||||
// Block all chunk operation during the update
|
||||
IntIterator iterator = new IntOpenHashSet(updatableBlocks).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int index = iterator.nextInt();
|
||||
CustomBlock customBlock = getCustomBlock(index);
|
||||
final int index = iterator.nextInt();
|
||||
final CustomBlock customBlock = getCustomBlock(index);
|
||||
|
||||
// Update cooldown
|
||||
UpdateOption updateOption = customBlock.getUpdateOption();
|
||||
long lastUpdate = updatableBlocksLastUpdate.get(index);
|
||||
boolean hasCooldown = CooldownUtils.hasCooldown(time, lastUpdate, updateOption.getTimeUnit(), updateOption.getValue());
|
||||
final UpdateOption updateOption = customBlock.getUpdateOption();
|
||||
final long lastUpdate = updatableBlocksLastUpdate.get(index);
|
||||
final boolean hasCooldown = CooldownUtils.hasCooldown(time, lastUpdate, updateOption);
|
||||
if (hasCooldown)
|
||||
continue;
|
||||
|
||||
this.updatableBlocksLastUpdate.put(index, time); // Refresh last update time
|
||||
|
||||
int[] blockPos = ChunkUtils.indexToPosition(index, chunkX, chunkZ);
|
||||
final int[] blockPos = ChunkUtils.indexToPosition(index, chunkX, chunkZ);
|
||||
int x = blockPos[0];
|
||||
int y = blockPos[1];
|
||||
int z = blockPos[2];
|
||||
|
@ -256,6 +256,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
|
||||
|
||||
/**
|
||||
* Get the instance dimension
|
||||
*
|
||||
* @return the dimension of the instance
|
||||
*/
|
||||
public Dimension getDimension() {
|
||||
@ -263,6 +265,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance world border
|
||||
*
|
||||
* @return the world border linked to the instance
|
||||
*/
|
||||
public WorldBorder getWorldBorder() {
|
||||
@ -270,6 +274,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the players in the instance
|
||||
*
|
||||
* @return an unmodifiable list containing all the players in the instance
|
||||
*/
|
||||
public Set<Player> getPlayers() {
|
||||
@ -277,6 +283,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creatures in the instance
|
||||
*
|
||||
* @return an unmodifiable list containing all the creatures in the instance
|
||||
*/
|
||||
public Set<EntityCreature> getCreatures() {
|
||||
@ -284,6 +292,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object entities in the instance
|
||||
*
|
||||
* @return an unmodifiable list containing all the object entities in the instance
|
||||
*/
|
||||
public Set<ObjectEntity> getObjectEntities() {
|
||||
@ -291,6 +301,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the experience orbs in the instance
|
||||
*
|
||||
* @return an unmodifiable list containing all the experience orbs in the instance
|
||||
*/
|
||||
public Set<ExperienceOrb> getExperienceOrbs() {
|
||||
@ -298,6 +310,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entities located in the chunk
|
||||
*
|
||||
* @param chunk the chunk to get the entities from
|
||||
* @return an unmodifiable set containing all the entities in a chunk,
|
||||
* if {@code chunk} is null, return an empty {@link HashSet}
|
||||
@ -412,6 +426,11 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
saveChunksToStorageFolder(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance unique id
|
||||
*
|
||||
* @return the instance unique id
|
||||
*/
|
||||
public UUID getUniqueId() {
|
||||
return uniqueId;
|
||||
}
|
||||
@ -517,7 +536,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Add the specified entity to the instance entities cache
|
||||
* <p>
|
||||
* Warning: this is done automatically the entity move out of his chunk
|
||||
* Warning: this is done automatically when the entity move out of his chunk
|
||||
*
|
||||
* @param entity the entity to add
|
||||
* @param chunk the chunk where the entity will be added
|
||||
@ -547,7 +566,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Remove the specified entity to the instance entities cache
|
||||
* <p>
|
||||
* Warning: this is done automatically the entity move out of his chunk
|
||||
* Warning: this is done automatically when the entity move out of his chunk
|
||||
*
|
||||
* @param entity the entity to remove
|
||||
* @param chunk the chunk where the entity will be removed
|
||||
@ -604,27 +623,29 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
* If no {@link ExplosionSupplier} was supplied, this method will throw an {@link IllegalStateException}
|
||||
* Creates an explosion at the given position with the given strength.
|
||||
* The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
*
|
||||
* @param centerX
|
||||
* @param centerY
|
||||
* @param centerZ
|
||||
* @param strength
|
||||
* @throws IllegalStateException If no {@link ExplosionSupplier} was supplied
|
||||
*/
|
||||
public void explode(float centerX, float centerY, float centerZ, float strength) {
|
||||
explode(centerX, centerY, centerZ, strength, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
* If no {@link ExplosionSupplier} was supplied, this method will throw an {@link IllegalStateException}
|
||||
* Creates an explosion at the given position with the given strength.
|
||||
* The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
*
|
||||
* @param centerX
|
||||
* @param centerY
|
||||
* @param centerZ
|
||||
* @param strength
|
||||
* @param additionalData data to pass to the explosion supplier
|
||||
* @throws IllegalStateException If no {@link ExplosionSupplier} was supplied
|
||||
*/
|
||||
public void explode(float centerX, float centerY, float centerZ, float strength, Data additionalData) {
|
||||
ExplosionSupplier explosionSupplier = getExplosionSupplier();
|
||||
@ -637,7 +658,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Return the registered explosion supplier, or null if none was provided
|
||||
*
|
||||
* @return
|
||||
* @return the instance explosion supplier, null if none was provided
|
||||
*/
|
||||
public ExplosionSupplier getExplosionSupplier() {
|
||||
return explosionSupplier;
|
||||
@ -646,7 +667,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Registers the explosion supplier to use in this instance
|
||||
*
|
||||
* @param supplier
|
||||
* @param supplier the explosion supplier
|
||||
*/
|
||||
public void setExplosionSupplier(ExplosionSupplier supplier) {
|
||||
this.explosionSupplier = supplier;
|
||||
|
@ -224,6 +224,10 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
Chunk chunk = getChunkAt(blockPosition);
|
||||
|
||||
// Chunk unloaded, stop here
|
||||
if (ChunkUtils.isChunkUnloaded(chunk))
|
||||
return false;
|
||||
|
||||
int x = blockPosition.getX();
|
||||
int y = blockPosition.getY();
|
||||
int z = blockPosition.getZ();
|
||||
@ -254,7 +258,7 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
chunk.getViewers().forEach(p -> {
|
||||
// The player who breaks the block already get particles client-side
|
||||
if (customBlock == null || !(p.equals(player) && player.isCreative())) {
|
||||
if (customBlock != null || !(p.equals(player) && !player.isCreative())) {
|
||||
p.getPlayerConnection().sendPacket(particlePacket);
|
||||
}
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class InstanceManager {
|
||||
public final class InstanceManager {
|
||||
|
||||
private ExecutorService blocksPool = new MinestomThread(MinecraftServer.THREAD_COUNT_BLOCK_UPDATE, MinecraftServer.THREAD_NAME_BLOCK_UPDATE);
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ConnectionManager {
|
||||
public final class ConnectionManager {
|
||||
|
||||
private Set<Player> players = new CopyOnWriteArraySet<>();
|
||||
private Map<PlayerConnection, Player> connectionPlayerMap = Collections.synchronizedMap(new HashMap<>());
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.scoreboard;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class TeamManager {
|
||||
public final class TeamManager {
|
||||
|
||||
// Represents all registered teams
|
||||
private Set<Team> teams = new CopyOnWriteArraySet<>();
|
||||
|
Loading…
Reference in New Issue
Block a user