This commit is contained in:
themode 2020-10-12 02:56:30 +02:00
parent af1f976e53
commit cbe2a0b71e
16 changed files with 77 additions and 55 deletions

View File

@ -13,9 +13,9 @@ import java.util.concurrent.CopyOnWriteArraySet;
/**
* Represents a boss bar which is displayed on the top of the client screen (max amount of boss bar defined by {@link #MAX_BOSSBAR}).
* <p>
* To use it, create a new instance and add the players you want using {@link #addViewer(Player)} and remove them using {@link #removeViewer(Player)}.
* To use it, create a new instance and add the {@link Player} you want using {@link #addViewer(Player)} and remove them using {@link #removeViewer(Player)}.
* <p>
* You can retrieve all the boss bars of a player with {@link #getBossBars(Player)}.
* You can retrieve all the boss bars of a {@link Player} with {@link #getBossBars(Player)}.
*/
public class BossBar implements Viewable {

View File

@ -126,6 +126,7 @@ public final class CommandManager {
Check.notNull(sender, "Source cannot be null");
Check.notNull(command, "Command string cannot be null");
// Command event
if (sender instanceof Player) {
Player player = (Player) sender;
@ -138,14 +139,15 @@ public final class CommandManager {
command = playerCommandEvent.getCommand();
}
// Process the command
try {
// Check for rich-command
this.dispatcher.execute(sender, command);
return true;
} catch (NullPointerException e) {
// Check for legacy-command
final String[] splitted = command.split(" ");
final String commandName = splitted[0];
final String[] splitCommand = command.split(" ");
final String commandName = splitCommand[0];
final CommandProcessor commandProcessor = commandProcessorMap.get(commandName.toLowerCase());
if (commandProcessor == null)
return false;
@ -170,7 +172,7 @@ public final class CommandManager {
/**
* Get the {@link DeclareCommandsPacket} for a specific player
* <p>
* Can be used to update the player auto-completion list
* Can be used to update the {@link Player} auto-completion list
*
* @param player the player to get the commands packet
* @return the {@link DeclareCommandsPacket} for {@code player}
@ -180,7 +182,7 @@ public final class CommandManager {
}
/**
* Build the {@link DeclareCommandsPacket} for a player
* Build the {@link DeclareCommandsPacket} for a {@link Player}
*
* @param player the player to build the packet for
* @return the commands packet for the specific player

View File

@ -91,7 +91,7 @@ public interface CommandSender {
}
/**
* Get if the sender is a player
* Get if the sender is a {@link Player}.
*
* @return true if 'this' is a player, false otherwise
*/
@ -100,7 +100,7 @@ public interface CommandSender {
}
/**
* Get if the sender is the console
* Get if the sender is a {@link ConsoleSender}.
*
* @return true if 'this' is the console, false otherwise
*/
@ -109,8 +109,8 @@ public interface CommandSender {
}
/**
* Casts this object to a {@link Player}
* No checks are performed, {@link ClassCastException} can very much happen
* Casts this object to a {@link Player}.
* No checks are performed, {@link ClassCastException} can very much happen.
*
* @see #isPlayer()
*/
@ -119,8 +119,8 @@ public interface CommandSender {
}
/**
* Casts this object to a {@link ConsoleSender}
* No checks are performed, {@link ClassCastException} can very much happen
* Casts this object to a {@link ConsoleSender}.
* No checks are performed, {@link ClassCastException} can very much happen.
*
* @see #isConsole()
*/

View File

@ -4,7 +4,9 @@ import java.util.Collections;
import java.util.Set;
/**
* Represent an object which contain key/value based data
* Represent an object which contain key/value based data.
* <p>
* Please see {@link DataImpl} for the default implementation.
*/
public interface Data {

View File

@ -1,19 +1,24 @@
package net.minestom.server.data;
/**
* Represent an element which can have a {@link Data} attached to it
* Represents an element which can have a {@link Data} attached to it.
* <p>
* The data will always be optional.
*/
public interface DataContainer {
/**
* Get the {@link Data} of this container
* Get the {@link Data} of this container.
* <p>
* A {@link DataContainer} data is always optional,
* meaning that this will be null if no data has been defined.
*
* @return the {@link Data} of this container, can be null
*/
Data getData();
/**
* Set the {@link Data} of this container
* Set the {@link Data} of this container.
*
* @param data the {@link Data} of this container, null to remove it
*/

View File

@ -7,7 +7,9 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
/**
* Represent a {@link Data} object which can be serialized and read back
* Represent a {@link Data} object which can be serialized and read back.
* <p>
* Please see {@link SerializableDataImpl} for the default implementation.
*/
public interface SerializableData extends Data {

View File

@ -9,8 +9,8 @@ import java.util.Collection;
import java.util.function.Function;
/**
* Called every time a player write and send something in the chat.
* The event can be cancelled to do not send anything, and the format can be changed
* Called every time a {@link Player} write and send something in the chat.
* The event can be cancelled to do not send anything, and the format can be changed.
*/
public class PlayerChatEvent extends CancellableEvent {
@ -44,7 +44,7 @@ public class PlayerChatEvent extends CancellableEvent {
}
/**
* This is all the players who will receive the message
* This is all the {@link Player} who will receive the message
* It can be modified to add or remove recipient
*
* @return a modifiable list of message targets

View File

@ -5,7 +5,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.Event;
/**
* Called when a player interacts (right-click) with an entity
* Called when a {@link Player} interacts (right-click) with an {@link Entity}
*/
public class PlayerEntityInteractEvent extends Event {
@ -20,18 +20,18 @@ public class PlayerEntityInteractEvent extends Event {
}
/**
* Get the player who is interacting
* Get the {@link Player} who is interacting
*
* @return the player
* @return the {@link Player}
*/
public Player getPlayer() {
return player;
}
/**
* Get the entity with who {@link #getPlayer()} is interacting
* Get the {@link Entity} with who {@link #getPlayer()} is interacting
*
* @return the entity
* @return the {@link Entity}
*/
public Entity getTarget() {
return entityTarget;

View File

@ -5,8 +5,8 @@ import net.minestom.server.event.CancellableEvent;
import net.minestom.server.utils.BlockPosition;
/**
* Called when a player start digging a block,
* can be used to forbid the player from mining it.
* Called when a {@link Player} start digging a block,
* can be used to forbid the {@link Player} from mining it.
*/
public class PlayerStartDiggingEvent extends CancellableEvent {
@ -23,18 +23,18 @@ public class PlayerStartDiggingEvent extends CancellableEvent {
}
/**
* Get the player who started digging the block
* Get the {@link Player} who started digging the block
*
* @return the player
* @return the {@link Player}
*/
public Player getPlayer() {
return player;
}
/**
* Get the block position
* Get the {@link BlockPosition}
*
* @return the block position
* @return the {@link BlockPosition}
*/
public BlockPosition getBlockPosition() {
return blockPosition;

View File

@ -3,13 +3,13 @@ package net.minestom.server.instance;
import net.minestom.server.utils.chunk.ChunkCallback;
/**
* Interface implemented to change the way chunks are loaded/saved
* see {@link MinestomBasicChunkLoader} for the default implementation used in {@link InstanceContainer}
* Interface implemented to change the way chunks are loaded/saved.
* See {@link MinestomBasicChunkLoader} for the default implementation used in {@link InstanceContainer}.
*/
public interface IChunkLoader {
/**
* Load a specific chunk, all blocks should be set since the {@link ChunkGenerator} is not applied
* Load a {@link Chunk}, all blocks should be set since the {@link ChunkGenerator} is not applied
*
* @param instance the instance where the chunk belong
* @param chunkX the chunk X
@ -21,7 +21,7 @@ public interface IChunkLoader {
boolean loadChunk(Instance instance, int chunkX, int chunkZ, ChunkCallback callback);
/**
* Save a specific chunk with a callback for when it is done
* Save a {@link Chunk} with a callback for when it is done
*
* @param chunk the chunk to save
* @param callback the callback executed when the chunk is done saving,
@ -30,7 +30,7 @@ public interface IChunkLoader {
void saveChunk(Chunk chunk, Runnable callback);
/**
* Does this ChunkLoader allow for multi-threaded saving of chunks?
* Does this {@link IChunkLoader} allow for multi-threaded saving of {@link Chunk}?
*
* @return true if the chunk loader supports parallel saving
*/
@ -39,7 +39,7 @@ public interface IChunkLoader {
}
/**
* Does this ChunkLoader allow for multi-threaded loading of chunks?
* Does this {@link IChunkLoader} allow for multi-threaded loading of {@link Chunk}?
*
* @return true if the chunk loader supports parallel loading
*/

View File

@ -214,26 +214,26 @@ public final class ConnectionManager {
}
/**
* Those are all the consumers called when a new player join
* Those are all the consumers called when a new {@link Player} join
*
* @return an unmodifiable list containing all the player initialization consumer
* @return an unmodifiable list containing all the {@link Player} initialization consumer
*/
public List<Consumer<Player>> getPlayerInitializations() {
return Collections.unmodifiableList(playerInitializations);
}
/**
* Add a new player initialization consumer. Those are called when a player join,
* Add a new player initialization consumer. Those are called when a {@link Player} join,
* mainly to add event callbacks to the player
*
* @param playerInitialization the player initialization consumer
* @param playerInitialization the {@link Player} initialization consumer
*/
public void addPlayerInitialization(Consumer<Player> playerInitialization) {
this.playerInitializations.add(playerInitialization);
}
/**
* Add a new player in the players list
* Add a new {@link Player} in the players list
* Is currently used at
* {@link LoginStartPacket#process(PlayerConnection)}
* and in {@link FakePlayer#initPlayer(UUID, String, Consumer)}
@ -246,7 +246,7 @@ public final class ConnectionManager {
}
/**
* Create a player object and register it
* Create a {@link Player} object and register it
*
* @param uuid the new player uuid
* @param username the new player username
@ -258,8 +258,8 @@ public final class ConnectionManager {
}
/**
* Remove a player from the players list
* used at player disconnection
* Remove a {@link Player} from the players list
* used during disconnection
*
* @param connection the player connection
*/

View File

@ -1,7 +1,9 @@
package net.minestom.server.network;
import net.minestom.server.entity.Player;
/**
* Represent the current connection state of a player
* Represent the current connection state of a {@link Player}
*/
public enum ConnectionState {
UNKNOWN, STATUS, LOGIN, PLAY

View File

@ -14,14 +14,16 @@ import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
/**
* Utils class used to write packets in the appropriate thread pool
* Utils class used to write {@link ServerPacket} in the appropriate thread pool.
* <p>
* WARNING: those methods do not guarantee a receive order.
*/
public final class PacketWriterUtils {
private static final ExecutorService PACKET_WRITER_POOL = new MinestomThread(MinecraftServer.THREAD_COUNT_PACKET_WRITER, MinecraftServer.THREAD_NAME_PACKET_WRITER);
/**
* Write the packet in the writer thread pool
* Write the {@link ServerPacket} in the writer thread pool.
* <p>
* WARNING: should not be used if the packet receive order is important
*
@ -36,7 +38,7 @@ public final class PacketWriterUtils {
}
/**
* Write a packet in the writer thread pool and send it to every players in {@code players}
* Write a {@link ServerPacket} in the writer thread pool and send it to every players in {@code players}.
* <p>
* WARNING: should not be used if the packet receive order is important
*
@ -62,7 +64,7 @@ public final class PacketWriterUtils {
}
/**
* Write a packet and send it to a player connection
* Write a {@link ServerPacket} and send it to a {@link PlayerConnection}.
* <p>
* WARNING: should not be used if the packet receive order is important
*
@ -71,12 +73,18 @@ public final class PacketWriterUtils {
*/
public static void writeAndSend(PlayerConnection playerConnection, ServerPacket serverPacket) {
PACKET_WRITER_POOL.execute(() -> {
playerConnection.sendPacket(serverPacket);
if (PlayerUtils.isNettyClient(playerConnection)) {
final ByteBuf buffer = PacketUtils.writePacket(serverPacket);
playerConnection.writePacket(buffer, true);
buffer.release();
} else {
playerConnection.sendPacket(serverPacket);
}
});
}
/**
* Write a packet and send it to a player
* Write a {@link ServerPacket} and send it to a {@link Player}.
* <p>
* WARNING: should not be used if the packet receive order is important
*

View File

@ -10,7 +10,7 @@ import net.minestom.server.utils.binary.BinaryWriter;
import java.util.Optional;
/**
* Packet sent during combat to a player.
* Packet sent during combat to a {@link Player}.
* Only death is supported for the moment (other events are ignored anyway as of 1.15.2)
*/
public class CombatEventPacket implements ServerPacket {

View File

@ -16,7 +16,7 @@ import java.net.SocketAddress;
import java.util.concurrent.atomic.AtomicInteger;
/**
* A PlayerConnection is an object needed for all created player
* A PlayerConnection is an object needed for all created {@link Player}
* It can be extended to create a new kind of player (NPC for instance)
*/
public abstract class PlayerConnection {

View File

@ -1,9 +1,10 @@
package net.minestom.server.resourcepack;
import net.minestom.server.entity.Player;
import net.minestom.server.utils.validate.Check;
/**
* Represent a resource pack which can be send to a player
* Represents a resource pack which can be send to a {@link Player}.
*/
public class ResourcePack {