mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Explanation for ResponseDataConsumer ang general comment cleanup
This commit is contained in:
parent
3e4ccbe75a
commit
ac362cf7ac
@ -1,12 +1,12 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
/**
|
||||
* Represent a click event for a specific portion of the message
|
||||
* Represents a click event for a specific portion of the message.
|
||||
*/
|
||||
public class ChatClickEvent {
|
||||
|
||||
private String action;
|
||||
private String value;
|
||||
private final String action;
|
||||
private final String value;
|
||||
|
||||
private ChatClickEvent(String action, String value) {
|
||||
this.action = action;
|
||||
|
@ -2,12 +2,11 @@ package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
/**
|
||||
* Represent a hover event for a specific portion of the message
|
||||
* Represents a hover event for a specific portion of the message.
|
||||
*/
|
||||
public class ChatHoverEvent {
|
||||
|
||||
|
@ -10,10 +10,10 @@ import java.util.List;
|
||||
// TODO format retention
|
||||
|
||||
/**
|
||||
* Represent multiple {@link ColoredText} batched together with the possibility to add
|
||||
* click and hover events
|
||||
* Represents multiple {@link ColoredText} batched together with the possibility to add
|
||||
* click and hover events.
|
||||
* <p>
|
||||
* Used when the message can contain both colored text and event (otherwise, use {@link ColoredText})
|
||||
* Used when the message can contain both colored text and event (otherwise, use {@link ColoredText}).
|
||||
*/
|
||||
public class RichMessage extends JsonMessage {
|
||||
|
||||
@ -200,7 +200,7 @@ public class RichMessage extends JsonMessage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent a colored text with a click and hover event (can be null)
|
||||
* Represents a colored text with a click and hover event (can be null).
|
||||
*/
|
||||
private static class RichComponent {
|
||||
|
||||
|
@ -6,9 +6,9 @@ import net.minestom.server.permission.Permission;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Represent something which can send commands to the server
|
||||
* Represents something which can send commands to the server.
|
||||
* <p>
|
||||
* Main implementations are {@link Player} and {@link ConsoleSender}
|
||||
* Main implementations are {@link Player} and {@link ConsoleSender}.
|
||||
*/
|
||||
public interface CommandSender {
|
||||
|
||||
|
@ -7,7 +7,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represent the console when sending a command to the server
|
||||
* Represents the console when sending a command to the server.
|
||||
*/
|
||||
public class ConsoleSender implements CommandSender {
|
||||
|
||||
|
@ -10,7 +10,7 @@ import net.minestom.server.command.builder.arguments.Argument;
|
||||
public interface ArgumentCallback {
|
||||
|
||||
/**
|
||||
* Executed when an error is found
|
||||
* Executed when an error is found.
|
||||
*
|
||||
* @param source the sender which executed the command
|
||||
* @param value the raw string argument which is responsible for the error
|
||||
|
@ -2,6 +2,11 @@ package net.minestom.server.command.builder;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Callback executed once a syntax has been found for a {@link Command}.
|
||||
* <p>
|
||||
* Warning: it could be the default executor from {@link Command#getDefaultExecutor()} if not null.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CommandExecutor {
|
||||
void apply(CommandSender source, Arguments args);
|
||||
|
@ -21,7 +21,7 @@ public class ArgumentBoolean extends Argument<Boolean> {
|
||||
|
||||
@Override
|
||||
public Boolean parse(String value) {
|
||||
return Boolean.valueOf(value);
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,16 +16,16 @@ public class ArgumentString extends Argument<String> {
|
||||
@Override
|
||||
public int getCorrectionResult(String value) {
|
||||
// Check if value start and end with quote
|
||||
char first = value.charAt(0);
|
||||
char last = value.charAt(value.length() - 1);
|
||||
boolean quote = first == '\"' && last == '\"';
|
||||
final char first = value.charAt(0);
|
||||
final char last = value.charAt(value.length() - 1);
|
||||
final boolean quote = first == '\"' && last == '\"';
|
||||
if (!quote)
|
||||
return QUOTE_ERROR;
|
||||
|
||||
for (int i = 1; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
final char c = value.charAt(i);
|
||||
if (c == '\"') {
|
||||
char lastChar = value.charAt(i - 1);
|
||||
final char lastChar = value.charAt(i - 1);
|
||||
if (lastChar == '\\') {
|
||||
continue;
|
||||
} else if (i == value.length() - 1) {
|
||||
|
@ -18,7 +18,7 @@ public class ArgumentColor extends Argument<ChatColor> {
|
||||
|
||||
@Override
|
||||
public int getCorrectionResult(String value) {
|
||||
ChatColor color = ChatColor.fromName(value);
|
||||
final ChatColor color = ChatColor.fromName(value);
|
||||
return color == ChatColor.NO_COLOR ? UNDEFINED_COLOR : SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -47,29 +47,29 @@ public class ArgumentFloatRange extends ArgumentRange<FloatRange> {
|
||||
public FloatRange parse(String value) {
|
||||
if (value.contains("..")) {
|
||||
final int index = value.indexOf('.');
|
||||
String[] split = value.split(Pattern.quote(".."));
|
||||
final String[] split = value.split(Pattern.quote(".."));
|
||||
|
||||
final float min;
|
||||
final float max;
|
||||
if (index == 0) {
|
||||
// Format ..NUMBER
|
||||
min = Float.MIN_VALUE;
|
||||
max = Float.valueOf(split[0]);
|
||||
max = Float.parseFloat(split[0]);
|
||||
} else {
|
||||
if (split.length == 2) {
|
||||
// Format NUMBER..NUMBER
|
||||
min = Float.valueOf(split[0]);
|
||||
max = Float.valueOf(split[1]);
|
||||
min = Float.parseFloat(split[0]);
|
||||
max = Float.parseFloat(split[1]);
|
||||
} else {
|
||||
// Format NUMBER..
|
||||
min = Float.valueOf(split[0]);
|
||||
min = Float.parseFloat(split[0]);
|
||||
max = Float.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return new FloatRange(min, max);
|
||||
} else {
|
||||
final float number = Float.valueOf(value);
|
||||
final float number = Float.parseFloat(value);
|
||||
return new FloatRange(number);
|
||||
}
|
||||
}
|
||||
|
@ -47,29 +47,29 @@ public class ArgumentIntRange extends ArgumentRange<IntRange> {
|
||||
public IntRange parse(String value) {
|
||||
if (value.contains("..")) {
|
||||
final int index = value.indexOf('.');
|
||||
String[] split = value.split(Pattern.quote(".."));
|
||||
final String[] split = value.split(Pattern.quote(".."));
|
||||
|
||||
final int min;
|
||||
final int max;
|
||||
if (index == 0) {
|
||||
// Format ..NUMBER
|
||||
min = Integer.MIN_VALUE;
|
||||
max = Integer.valueOf(split[0]);
|
||||
max = Integer.parseInt(split[0]);
|
||||
} else {
|
||||
if (split.length == 2) {
|
||||
// Format NUMBER..NUMBER
|
||||
min = Integer.valueOf(split[0]);
|
||||
max = Integer.valueOf(split[1]);
|
||||
min = Integer.parseInt(split[0]);
|
||||
max = Integer.parseInt(split[1]);
|
||||
} else {
|
||||
// Format NUMBER..
|
||||
min = Integer.valueOf(split[0]);
|
||||
min = Integer.parseInt(split[0]);
|
||||
max = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return new IntRange(min, max);
|
||||
} else {
|
||||
final int number = Integer.valueOf(value);
|
||||
final int number = Integer.parseInt(value);
|
||||
return new IntRange(number);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,8 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assert compound != null;
|
||||
|
||||
NBTUtils.loadDataIntoItem(itemStack, compound);
|
||||
|
||||
return itemStack;
|
||||
|
@ -4,7 +4,7 @@ import net.minestom.server.item.Enchantment;
|
||||
import net.minestom.server.registry.Registries;
|
||||
|
||||
/**
|
||||
* Represent an argument giving an item enchantment
|
||||
* Represents an argument giving an {@link Enchantment}.
|
||||
*/
|
||||
public class ArgumentEnchantment extends ArgumentRegistry<Enchantment> {
|
||||
|
||||
|
@ -4,7 +4,7 @@ import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.registry.Registries;
|
||||
|
||||
/**
|
||||
* Represent an argument giving an entity type
|
||||
* Represents an argument giving an {@link EntityType}.
|
||||
*/
|
||||
public class ArgumentEntityType extends ArgumentRegistry<EntityType> {
|
||||
|
||||
|
@ -4,7 +4,7 @@ import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.registry.Registries;
|
||||
|
||||
/**
|
||||
* Represent an argument giving a particle type
|
||||
* Represents an argument giving a {@link Particle}.
|
||||
*/
|
||||
public class ArgumentParticle extends ArgumentRegistry<Particle> {
|
||||
|
||||
|
@ -24,7 +24,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represent the handler of a custom block type.
|
||||
* Represents the handler of a custom block type.
|
||||
* <p>
|
||||
* There should be only one instance of this class for each custom block type,
|
||||
* every individual blocks will execute the callbacks present there. Each of which contains the
|
||||
|
@ -6,10 +6,10 @@ import net.minestom.server.inventory.click.ClickType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Represent an inventory which can receive click input
|
||||
* all methods returning boolean returns true if the action is successful, false otherwise
|
||||
* Represents an inventory which can receive click input.
|
||||
* All methods returning boolean returns true if the action is successful, false otherwise.
|
||||
* <p>
|
||||
* See https://wiki.vg/Protocol#Click_Window for more information
|
||||
* See https://wiki.vg/Protocol#Click_Window for more information.
|
||||
*/
|
||||
public interface InventoryClickHandler {
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class FurnaceInventory extends Inventory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent the amount of tick until the fire icon come empty
|
||||
* Represents the amount of tick until the fire icon come empty.
|
||||
*
|
||||
* @return the amount of tick until the fire icon come empty
|
||||
*/
|
||||
@ -25,7 +25,7 @@ public class FurnaceInventory extends Inventory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent the amount of tick until the fire icon come empty
|
||||
* Represents the amount of tick until the fire icon come empty.
|
||||
*
|
||||
* @param remainingFuelTick
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.network;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
/**
|
||||
* Represent the current connection state of a {@link Player}
|
||||
* Represents the current connection state of a {@link Player}.
|
||||
*/
|
||||
public enum ConnectionState {
|
||||
UNKNOWN, STATUS, LOGIN, PLAY
|
||||
|
@ -15,8 +15,9 @@ import javax.crypto.SecretKey;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* Represent a networking connection with Netty
|
||||
* It is the implementation used for all server connection client
|
||||
* Represents a networking connection with Netty.
|
||||
* <p>
|
||||
* It is the implementation used for all network client.
|
||||
*/
|
||||
public class NettyPlayerConnection extends PlayerConnection {
|
||||
|
||||
|
@ -8,23 +8,25 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represent the data sent to the player when refreshing his server list
|
||||
* Represents the data sent to the player when refreshing the server list.
|
||||
* <p>
|
||||
* Filled by {@link ResponseDataConsumer} and specified in {@link net.minestom.server.MinecraftServer#start(String, int, ResponseDataConsumer)}.
|
||||
*/
|
||||
public class ResponseData {
|
||||
|
||||
private JsonObject jsonObject = new JsonObject();
|
||||
private final JsonObject jsonObject = new JsonObject();
|
||||
|
||||
private JsonObject versionObject = new JsonObject();
|
||||
private JsonObject playersObject = new JsonObject();
|
||||
private JsonArray sampleArray = new JsonArray();
|
||||
private JsonObject descriptionObject = new JsonObject();
|
||||
private final JsonObject versionObject = new JsonObject();
|
||||
private final JsonObject playersObject = new JsonObject();
|
||||
private final JsonArray sampleArray = new JsonArray();
|
||||
private final JsonObject descriptionObject = new JsonObject();
|
||||
|
||||
private String name;
|
||||
private int protocol;
|
||||
|
||||
private int maxPlayer;
|
||||
private int online;
|
||||
private List<PingPlayer> pingPlayers = new ArrayList<>();
|
||||
private final List<PingPlayer> pingPlayers = new ArrayList<>();
|
||||
|
||||
private String description;
|
||||
|
||||
@ -61,6 +63,11 @@ public class ResponseData {
|
||||
this.favicon = favicon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the response data into a {@link JsonObject}.
|
||||
*
|
||||
* @return the converted json data
|
||||
*/
|
||||
public JsonObject build() {
|
||||
versionObject.addProperty("name", name);
|
||||
versionObject.addProperty("protocol", protocol);
|
||||
@ -85,6 +92,9 @@ public class ResponseData {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a player line in the server list hover.
|
||||
*/
|
||||
private static class PingPlayer {
|
||||
private String name;
|
||||
private UUID uuid;
|
||||
|
@ -2,6 +2,11 @@ package net.minestom.server.ping;
|
||||
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
||||
/**
|
||||
* Consumer used to fill a {@link ResponseData} object before being sent to a connection.
|
||||
* <p>
|
||||
* Can be specified in {@link net.minestom.server.MinecraftServer#start(String, int, ResponseDataConsumer)}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ResponseDataConsumer {
|
||||
void accept(PlayerConnection playerConnection, ResponseData responseData);
|
||||
|
@ -6,9 +6,11 @@ import net.minestom.server.utils.math.IntRange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO
|
||||
|
||||
/**
|
||||
* Represent a query which can be call to find one or multiple entities
|
||||
* It is based on the target selectors used in commands
|
||||
* Represents a query which can be call to find one or multiple entities.
|
||||
* It is based on the target selectors used in commands.
|
||||
*/
|
||||
public class EntityFinder {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user