mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-15 20:51:34 +01:00
slightly optimize CommandManager
This commit is contained in:
parent
f307303758
commit
6fd401589c
@ -2,7 +2,6 @@ package net.minestom.server.command;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.command.builder.Command;
|
import net.minestom.server.command.builder.Command;
|
||||||
import net.minestom.server.command.builder.CommandDispatcher;
|
import net.minestom.server.command.builder.CommandDispatcher;
|
||||||
import net.minestom.server.command.builder.CommandSyntax;
|
import net.minestom.server.command.builder.CommandSyntax;
|
||||||
@ -30,6 +29,9 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -55,25 +57,35 @@ public final class CommandManager {
|
|||||||
running = true;
|
running = true;
|
||||||
// Setup console thread
|
// Setup console thread
|
||||||
Thread consoleThread = new Thread(() -> {
|
Thread consoleThread = new Thread(() -> {
|
||||||
final Scanner scanner = new Scanner(System.in);
|
BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
|
||||||
while (running) {
|
while (running) {
|
||||||
if (scanner.hasNext()) {
|
|
||||||
String command = scanner.nextLine();
|
try {
|
||||||
if (!command.startsWith(COMMAND_PREFIX))
|
if (bi.ready()) {
|
||||||
continue;
|
String command = bi.readLine();
|
||||||
command = command.replaceFirst(COMMAND_PREFIX, "");
|
if (!command.startsWith(COMMAND_PREFIX))
|
||||||
execute(consoleSender, command);
|
continue;
|
||||||
|
command = command.replaceFirst(COMMAND_PREFIX, "");
|
||||||
|
execute(consoleSender, command);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent permanent looping
|
// Prevent permanent looping
|
||||||
try {
|
try {
|
||||||
Thread.sleep(MinecraftServer.TICK_MS);
|
Thread.sleep(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
scanner.close();
|
try {
|
||||||
|
bi.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}, "ConsoleCommand-Thread");
|
}, "ConsoleCommand-Thread");
|
||||||
consoleThread.setDaemon(true);
|
consoleThread.setDaemon(true);
|
||||||
consoleThread.start();
|
consoleThread.start();
|
||||||
|
@ -345,7 +345,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
// Flush all pending packets
|
// Flush all pending packets
|
||||||
if (PlayerUtils.isNettyClient(this)) {
|
if (PlayerUtils.isNettyClient(this)) {
|
||||||
Channel channel = ((NettyPlayerConnection) playerConnection).getChannel();
|
Channel channel = ((NettyPlayerConnection) playerConnection).getChannel();
|
||||||
channel.eventLoop().execute(() -> channel.flush());
|
channel.eventLoop().execute(channel::flush);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network tick verification
|
// Network tick verification
|
||||||
|
Loading…
Reference in New Issue
Block a user