Use TerminalConsoleAppender for console improvements

Rewrite console improvements (console colors, tab completion,
persistent input line, ...) using JLine 3.x and TerminalConsoleAppender.

Also uses the new ANSIComponentSerializer to serialize components when
logging them via the ComponentLogger, or when sending messages to the
console, for hex color support.

New features:
  - Support console colors for Vanilla commands
  - Add console colors for warnings and errors
  - Server can now be turned off safely using CTRL + C. JLine catches
    the signal and the implementation shuts down the server cleanly.
  - Support console colors and persistent input line when running in
    IntelliJ IDEA

Other changes:
  - Server starts 1-2 seconds faster thanks to optimizations in Log4j
    configuration

Co-Authored-By: Emilia Kond <emilia@rymiel.space>
This commit is contained in:
Minecrell
2017-06-09 19:03:43 +02:00
parent 66779f5c86
commit 36723cdd60
19 changed files with 343 additions and 133 deletions

View File

@@ -63,7 +63,7 @@
public final PlayerDataStorage playerIo;
private boolean doWhiteList;
private final LayeredRegistryAccess<RegistryLayer> registries;
@@ -134,13 +156,24 @@
@@ -134,13 +156,23 @@
private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn;
@@ -73,8 +73,7 @@
+
public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registryManager, PlayerDataStorage saveHandler, int maxPlayers) {
+ this.cserver = server.server = new CraftServer((DedicatedServer) server, this);
+ server.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance();
+ server.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(server.server));
+ server.console = new com.destroystokyo.paper.console.TerminalConsoleCommandSender(); // Paper
+ // CraftBukkit end
+
this.bans = new UserBanList(PlayerList.USERBANLIST_FILE);
@@ -90,7 +89,7 @@
this.server = server;
this.registries = registryManager;
this.maxPlayers = maxPlayers;
@@ -148,27 +181,37 @@
@@ -148,27 +180,37 @@
}
public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie clientData) {
@@ -133,7 +132,7 @@
ServerLevel worldserver = this.server.getLevel(resourcekey);
ServerLevel worldserver1;
@@ -182,10 +225,24 @@
@@ -182,10 +224,24 @@
player.setServerLevel(worldserver1);
String s1 = connection.getLoggableAddress(this.server.logIPs());
@@ -160,7 +159,7 @@
ServerGamePacketListenerImpl playerconnection = new ServerGamePacketListenerImpl(this.server, connection, player, clientData);
connection.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection);
@@ -194,7 +251,9 @@
@@ -194,7 +250,9 @@
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
@@ -171,7 +170,7 @@
playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
playerconnection.send(new ClientboundSetHeldSlotPacket(player.getInventory().selected));
@@ -213,8 +272,10 @@
@@ -213,8 +271,10 @@
} else {
ichatmutablecomponent = Component.translatable("multiplayer.player.joined.renamed", player.getDisplayName(), s);
}
@@ -183,7 +182,7 @@
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
ServerStatus serverping = this.server.getStatus();
@@ -222,17 +283,70 @@
@@ -222,17 +282,70 @@
player.sendServerStatus(serverping);
}
@@ -258,7 +257,7 @@
}
public void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) {
@@ -269,30 +383,31 @@
@@ -269,30 +382,31 @@
}
public void addWorldborderListener(ServerLevel world) {
@@ -295,7 +294,7 @@
}
@Override
@@ -319,14 +434,15 @@
@@ -319,14 +433,15 @@
}
protected void save(ServerPlayer player) {
@@ -313,7 +312,7 @@
if (advancementdataplayer != null) {
advancementdataplayer.save();
@@ -334,95 +450,176 @@
@@ -334,95 +449,176 @@
}
@@ -528,7 +527,7 @@
if (entityplayer1 != null) {
set.add(entityplayer1);
@@ -431,30 +628,50 @@
@@ -431,30 +627,50 @@
Iterator iterator1 = set.iterator();
while (iterator1.hasNext()) {
@@ -592,7 +591,7 @@
while (iterator.hasNext()) {
String s = (String) iterator.next();
@@ -462,41 +679,88 @@
@@ -462,41 +678,88 @@
entityplayer1.addTag(s);
}
@@ -689,7 +688,7 @@
return entityplayer1;
}
@@ -524,7 +788,18 @@
@@ -524,7 +787,18 @@
public void tick() {
if (++this.sendAllPlayerInfoIn > 600) {
@@ -709,7 +708,7 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -541,6 +816,25 @@
@@ -541,6 +815,25 @@
}
@@ -735,7 +734,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator();
@@ -554,7 +848,7 @@
@@ -554,7 +847,7 @@
}
@@ -744,7 +743,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam != null) {
@@ -573,7 +867,7 @@
@@ -573,7 +866,7 @@
}
}
@@ -753,7 +752,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam == null) {
@@ -619,7 +913,7 @@
@@ -619,7 +912,7 @@
}
public void deop(GameProfile profile) {
@@ -762,7 +761,7 @@
ServerPlayer entityplayer = this.getPlayer(profile.getId());
if (entityplayer != null) {
@@ -643,6 +937,7 @@
@@ -643,6 +936,7 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0));
}
@@ -770,7 +769,7 @@
this.server.getCommands().sendCommands(player);
}
@@ -656,23 +951,19 @@
@@ -656,23 +950,19 @@
@Nullable
public ServerPlayer getPlayerByName(String name) {
@@ -802,7 +801,7 @@
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX();
double d5 = y - entityplayer.getY();
@@ -712,15 +1003,19 @@
@@ -712,15 +1002,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
@@ -826,7 +825,7 @@
}
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -729,8 +1024,16 @@
@@ -729,8 +1023,16 @@
public void sendAllPlayerInfo(ServerPlayer player) {
player.inventoryMenu.sendAllDataToRemote();
@@ -844,7 +843,7 @@
}
public int getPlayerCount() {
@@ -786,12 +1089,22 @@
@@ -786,12 +1088,22 @@
}
public void removeAll() {
@@ -869,7 +868,7 @@
public void broadcastSystemMessage(Component message, boolean overlay) {
this.broadcastSystemMessage(message, (entityplayer) -> {
return message;
@@ -819,24 +1132,43 @@
@@ -819,24 +1131,43 @@
}
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
@@ -916,7 +915,7 @@
}
if (flag1 && sender != null) {
@@ -845,20 +1177,27 @@
@@ -845,20 +1176,27 @@
}
@@ -949,7 +948,7 @@
Path path = file2.toPath();
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -867,7 +1206,7 @@
@@ -867,7 +1205,7 @@
}
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
@@ -958,7 +957,7 @@
}
return serverstatisticmanager;
@@ -875,13 +1214,13 @@
@@ -875,13 +1213,13 @@
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID();
@@ -974,7 +973,7 @@
}
advancementdataplayer.setPlayer(player);
@@ -932,15 +1271,28 @@
@@ -932,15 +1270,28 @@
}
public void reloadResources() {