mirror of
https://github.com/LOOHP/Limbo.git
synced 2026-06-07 21:41:43 +00:00
Updated pom.xml, handles interrupt signal
This commit is contained in:
@@ -20,10 +20,12 @@ import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Attribute;
|
||||
import org.jline.reader.Candidate;
|
||||
import org.jline.reader.Completer;
|
||||
import org.jline.reader.EndOfFileException;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.LineReader.SuggestionType;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.ParsedLine;
|
||||
import org.jline.reader.UserInterruptException;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
|
||||
@@ -85,7 +87,7 @@ public class Console implements CommandSender {
|
||||
|
||||
reader = new ConsoleReader(in, out);
|
||||
reader.setExpandEvents(false);
|
||||
|
||||
reader.setHandleUserInterrupt(false);
|
||||
|
||||
terminal = TerminalBuilder.builder().streams(in, out).system(true).jansi(true).build();
|
||||
tabReader = LineReaderBuilder.builder().terminal(terminal).completer(new Completer() {
|
||||
@@ -152,10 +154,16 @@ public class Console implements CommandSender {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
String command = tabReader.readLine(PROMPT).trim();
|
||||
if (command.length() > 0) {
|
||||
String[] input = CustomStringUtils.splitStringToArgs(command);
|
||||
new Thread(() -> Limbo.getInstance().dispatchCommand(this, input)).start();
|
||||
try {
|
||||
String command = tabReader.readLine(PROMPT).trim();
|
||||
if (command.length() > 0) {
|
||||
String[] input = CustomStringUtils.splitStringToArgs(command);
|
||||
new Thread(() -> Limbo.getInstance().dispatchCommand(this, input)).start();
|
||||
}
|
||||
} catch (UserInterruptException e) {
|
||||
System.exit(0);
|
||||
} catch (EndOfFileException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,6 +321,10 @@ public class Limbo {
|
||||
|
||||
metrics = new Metrics();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
Limbo.getInstance().terminate();
|
||||
}));
|
||||
|
||||
console.run();
|
||||
}
|
||||
|
||||
@@ -496,7 +500,7 @@ public class Limbo {
|
||||
return String.join("\00", begin, "127", version, String.join("", Arrays.asList(motd).stream().map(each -> each.toLegacyText()).collect(Collectors.toList())), String.valueOf(playersOnline), String.valueOf(maxPlayers));
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
protected void terminate() {
|
||||
isRunning.set(false);
|
||||
console.sendMessage("Stopping Server...");
|
||||
|
||||
@@ -520,6 +524,9 @@ public class Limbo {
|
||||
|
||||
console.sendMessage("Server closed");
|
||||
console.logs.close();
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -293,37 +293,26 @@ public class ClientConnection extends Thread {
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
|
||||
ServerProperties p = Limbo.getInstance().getServerProperties();
|
||||
Location s = p.getWorldSpawn();
|
||||
|
||||
PlayerJoinEvent evt = new PlayerJoinEvent(player, s);
|
||||
Limbo.getInstance().getEventsManager().callEvent(evt);
|
||||
s = evt.getSpawnLocation();
|
||||
|
||||
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, p.getDefaultGamemode(), Limbo.getInstance().getWorlds().stream().map(each -> new NamespacedKey(each.getName()).toString()).collect(Collectors.toList()).toArray(new String[Limbo.getInstance().getWorlds().size()]), Limbo.getInstance().getDimensionRegistry().getCodec(), p.getWorldSpawn().getWorld(), 0, (byte) p.getMaxPlayers(), 8, p.isReducedDebugInfo(), true, false, true);
|
||||
sendPacket(join);
|
||||
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, p.getDefaultGamemode());
|
||||
|
||||
//PacketPlayOutKeepAlive alive = new PacketPlayOutKeepAlive((long) (Math.random() * Long.MAX_VALUE));
|
||||
ServerProperties properties = Limbo.getInstance().getServerProperties();
|
||||
Location worldSpawn = properties.getWorldSpawn();
|
||||
|
||||
World world = s.getWorld();
|
||||
PlayerJoinEvent joinEvent = Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player, worldSpawn));
|
||||
worldSpawn = joinEvent.getSpawnLocation();
|
||||
World world = worldSpawn.getWorld();
|
||||
|
||||
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, properties.getDefaultGamemode(), Limbo.getInstance().getWorlds().stream().map(each -> new NamespacedKey(each.getName()).toString()).collect(Collectors.toList()).toArray(new String[Limbo.getInstance().getWorlds().size()]), Limbo.getInstance().getDimensionRegistry().getCodec(), world, 0, (byte) properties.getMaxPlayers(), 8, properties.isReducedDebugInfo(), true, false, true);
|
||||
sendPacket(join);
|
||||
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, properties.getDefaultGamemode());
|
||||
|
||||
player.playerInteractManager.update();
|
||||
|
||||
SkinResponse skinresponce = isBungeecord && bungeeSkin != null ? bungeeSkin : MojangAPIUtils.getSkinFromMojangServer(player.getName());
|
||||
PlayerSkinProperty skin = skinresponce != null ? new PlayerSkinProperty(skinresponce.getSkin(), skinresponce.getSignature()) : null;
|
||||
PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(PlayerInfoAction.ADD_PLAYER, player.getUniqueId(), new PlayerInfoData.PlayerInfoDataAddPlayer(player.getName(), Optional.ofNullable(skin), p.getDefaultGamemode(), 0, false, Optional.empty()));
|
||||
PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(PlayerInfoAction.ADD_PLAYER, player.getUniqueId(), new PlayerInfoData.PlayerInfoDataAddPlayer(player.getName(), Optional.ofNullable(skin), properties.getDefaultGamemode(), 0, false, Optional.empty()));
|
||||
sendPacket(info);
|
||||
/*
|
||||
for (ClientConnection client : Limbo.getInstance().getServerConnection().getClients()) {
|
||||
DataOutputStream other = new DataOutputStream(client.getSocket().getOutputStream());
|
||||
DataTypeIO.writeVarInt(other, packetByte.length);
|
||||
other.write(packetByte);
|
||||
}
|
||||
*/
|
||||
|
||||
Set<PlayerAbilityFlags> flags = new HashSet<>();
|
||||
if (p.isAllowFlight()) {
|
||||
if (properties.isAllowFlight()) {
|
||||
flags.add(PlayerAbilityFlags.FLY);
|
||||
}
|
||||
if (player.getGamemode().equals(GameMode.CREATIVE)) {
|
||||
@@ -340,11 +329,11 @@ public class ClientConnection extends Thread {
|
||||
sendPacket(declare);
|
||||
}
|
||||
|
||||
PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(s));
|
||||
PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(worldSpawn));
|
||||
sendPacket(spawnPos);
|
||||
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(s.getX(), s.getY(), s.getZ(), s.getYaw(), s.getPitch(), 1);
|
||||
Limbo.getInstance().getUnsafe().setPlayerLocationSilently(player, new Location(world, s.getX(), s.getY(), s.getZ(), s.getYaw(), s.getPitch()));
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), worldSpawn.getYaw(), worldSpawn.getPitch(), 1);
|
||||
Limbo.getInstance().getUnsafe().setPlayerLocationSilently(player, new Location(world, worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), worldSpawn.getYaw(), worldSpawn.getPitch()));
|
||||
sendPacket(positionLook);
|
||||
|
||||
player.getDataWatcher().update();
|
||||
|
||||
Reference in New Issue
Block a user