mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Update
This commit is contained in:
parent
3614c378f3
commit
18019277e6
@ -28,4 +28,9 @@ public class SimpleCommand implements CommandProcessor {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAccess(Player player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ public class UpdateManager {
|
||||
|
||||
// Keep Alive Handling
|
||||
for (Player player : connectionManager.getOnlinePlayers()) {
|
||||
long time = currentTime / 1_000_000;
|
||||
if (time - player.getLastKeepAlive() > 20000) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - player.getLastKeepAlive() > 10000) {
|
||||
player.refreshKeepAlive(time);
|
||||
KeepAlivePacket keepAlivePacket = new KeepAlivePacket(time);
|
||||
player.getPlayerConnection().sendPacket(keepAlivePacket);
|
||||
|
@ -2,11 +2,7 @@ package net.minestom.server.command;
|
||||
|
||||
import fr.themode.command.Command;
|
||||
import fr.themode.command.CommandDispatcher;
|
||||
import fr.themode.command.CommandSyntax;
|
||||
import fr.themode.command.arguments.*;
|
||||
import fr.themode.command.arguments.number.ArgumentDouble;
|
||||
import fr.themode.command.arguments.number.ArgumentFloat;
|
||||
import fr.themode.command.arguments.number.ArgumentInteger;
|
||||
import fr.themode.command.condition.CommandCondition;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
@ -23,16 +19,12 @@ public class CommandManager {
|
||||
private CommandDispatcher<Player> dispatcher = new CommandDispatcher<>();
|
||||
private Map<String, CommandProcessor> commandProcessorMap = new HashMap<>();
|
||||
|
||||
private DeclareCommandsPacket declareCommandsPacket = new DeclareCommandsPacket();
|
||||
|
||||
public void register(Command<Player> command) {
|
||||
this.dispatcher.register(command);
|
||||
refreshPacket();
|
||||
}
|
||||
|
||||
public void register(CommandProcessor commandProcessor) {
|
||||
this.commandProcessorMap.put(commandProcessor.getCommandName().toLowerCase(), commandProcessor);
|
||||
refreshPacket();
|
||||
}
|
||||
|
||||
public boolean execute(Player source, String command) {
|
||||
@ -66,19 +58,33 @@ public class CommandManager {
|
||||
this.commandPrefix = commandPrefix;
|
||||
}
|
||||
|
||||
public DeclareCommandsPacket getDeclareCommandsPacket() {
|
||||
return declareCommandsPacket;
|
||||
public DeclareCommandsPacket createDeclareCommandsPacket(Player player) {
|
||||
return buildPacket(player);
|
||||
}
|
||||
|
||||
private void refreshPacket() {
|
||||
private DeclareCommandsPacket buildPacket(Player player) {
|
||||
DeclareCommandsPacket declareCommandsPacket = new DeclareCommandsPacket();
|
||||
|
||||
List<String> commands = new ArrayList<>();
|
||||
for (Command<Player> command : dispatcher.getCommands()) {
|
||||
CommandCondition<Player> commandCondition = command.getCondition();
|
||||
if (commandCondition != null) {
|
||||
// Do not show command if return false
|
||||
if (!commandCondition.apply(player)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
commands.add(command.getName());
|
||||
for (String alias : command.getAliases()) {
|
||||
commands.add(alias);
|
||||
}
|
||||
}
|
||||
|
||||
for (CommandProcessor commandProcessor : commandProcessorMap.values()) {
|
||||
// Do not show command if return false
|
||||
if (!commandProcessor.hasAccess(player))
|
||||
continue;
|
||||
|
||||
commands.add(commandProcessor.getCommandName());
|
||||
String[] aliases = commandProcessor.getAliases();
|
||||
if (aliases == null || aliases.length == 0)
|
||||
@ -123,9 +129,11 @@ public class CommandManager {
|
||||
|
||||
declareCommandsPacket.nodes = nodes.toArray(new DeclareCommandsPacket.Node[nodes.size()]);
|
||||
declareCommandsPacket.rootIndex = nodes.size() - 1;
|
||||
|
||||
return declareCommandsPacket;
|
||||
}
|
||||
|
||||
private void refreshPacket2() {
|
||||
/*private void refreshPacket2() {
|
||||
|
||||
List<DeclareCommandsPacket.Node> nodes = new ArrayList<>();
|
||||
ArrayList<Integer> rootChildren = new ArrayList<>();
|
||||
@ -223,5 +231,5 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
return argumentNode;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ public interface CommandProcessor {
|
||||
String[] getAliases();
|
||||
|
||||
boolean process(Player player, String command, String[] args);
|
||||
|
||||
boolean hasAccess(Player player);
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ public class Player extends LivingEntity {
|
||||
private PlayerConnection playerConnection;
|
||||
private ConcurrentLinkedQueue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private int latency;
|
||||
|
||||
private Dimension dimension;
|
||||
private GameMode gameMode;
|
||||
private LevelType levelType;
|
||||
@ -590,6 +592,10 @@ public class Player extends LivingEntity {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public int getLatency() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
public Dimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
@ -834,6 +840,13 @@ public class Player extends LivingEntity {
|
||||
this.packets.add(packet);
|
||||
}
|
||||
|
||||
public void refreshLatency(int latency) {
|
||||
this.latency = latency;
|
||||
PlayerInfoPacket playerInfoPacket = new PlayerInfoPacket(PlayerInfoPacket.Action.UPDATE_LATENCY);
|
||||
playerInfoPacket.playerInfos.add(new PlayerInfoPacket.UpdateLatency(getUuid(), latency));
|
||||
sendPacketToViewersAndSelf(playerInfoPacket);
|
||||
}
|
||||
|
||||
public void refreshDimension(Dimension dimension) {
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
@ -13,12 +13,13 @@ public class AStarPathfinder {
|
||||
|
||||
// TODO ladder, jump, etc...
|
||||
|
||||
private boolean climbLadder;
|
||||
private boolean canClimbLadder;
|
||||
private boolean canSwim;
|
||||
private boolean canJump;
|
||||
|
||||
public static LinkedList<BlockPosition> getPath(Instance instance,
|
||||
BlockPosition start, BlockPosition end,
|
||||
int maxCheck) {
|
||||
long time = System.nanoTime();
|
||||
List<Node> open = new ArrayList<>();
|
||||
List<Node> closed = new ArrayList<>();
|
||||
|
||||
@ -35,7 +36,6 @@ public class AStarPathfinder {
|
||||
closed.add(current);
|
||||
|
||||
if (isTargetNode(end, current)) {
|
||||
//System.out.println("FOUND, RETURN: " + (System.nanoTime() - time));
|
||||
return buildPath(current);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ public class Chunk implements Viewable {
|
||||
|
||||
// Used to get all blocks with data (no null)
|
||||
// Key is still chunk coord
|
||||
// FIXME: shouldn't take Data object (too much memory overhead)
|
||||
private Int2ObjectMap<Data> blocksData = new Int2ObjectOpenHashMap<>(16 * 16); // Start with the size of a single row
|
||||
|
||||
// Contains CustomBlocks' index which are updatable
|
||||
|
@ -9,7 +9,12 @@ public class KeepAliveListener {
|
||||
public static void listener(ClientKeepAlivePacket packet, Player player) {
|
||||
if (packet.id != player.getLastKeepAlive()) {
|
||||
player.kick(ChatColor.RED + "Bad Keep Alive packet");
|
||||
return;
|
||||
}
|
||||
|
||||
// Update latency
|
||||
int latency = (int) (System.currentTimeMillis() - packet.id);
|
||||
player.refreshLatency(latency);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
{
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
DeclareCommandsPacket declareCommandsPacket = commandManager.getDeclareCommandsPacket();
|
||||
DeclareCommandsPacket declareCommandsPacket = commandManager.createDeclareCommandsPacket(player);
|
||||
|
||||
connection.sendPacket(declareCommandsPacket);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user