forked from BLOCKFANTASY/LOOHP-Limbo
reorganize classes for a better future
This commit is contained in:
parent
e8a7d68e3b
commit
2d77a0e15c
2
pom.xml
2
pom.xml
|
|
@ -5,7 +5,7 @@
|
|||
<groupId>com.loohp.limbo</groupId>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<name>Limbo</name>
|
||||
<version>0.4.1-ALPHA</version>
|
||||
<version>0.4.2-ALPHA</version>
|
||||
|
||||
<description>Standalone Limbo Minecraft Server.</description>
|
||||
<url>https://github.com/LOOHP/Limbo</url>
|
||||
|
|
|
|||
|
|
@ -103,10 +103,12 @@ public class Console implements CommandSender {
|
|||
tabReader.setAutosuggestion(SuggestionType.NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return CONSOLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return Limbo.getInstance().getPermissionsManager().hasPermission(this, permission);
|
||||
}
|
||||
|
|
@ -121,6 +123,7 @@ public class Console implements CommandSender {
|
|||
sendMessage(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message, UUID uuid) {
|
||||
sendMessage(message);
|
||||
}
|
||||
|
|
@ -135,6 +138,7 @@ public class Console implements CommandSender {
|
|||
sendMessage(String.join("", Arrays.asList(component).stream().map(each -> each.toLegacyText()).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
stashLine();
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.loohp.limbo.Entity;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
import com.loohp.limbo.Utils.NamespacedKey;
|
||||
import com.loohp.limbo.World.World;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Events.Cancellable;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Events.Event;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
public class PlayerEvent extends Event {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Events.Cancellable;
|
||||
import com.loohp.limbo.Events.Event;
|
||||
import com.loohp.limbo.Server.ClientConnection;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Events.Cancellable;
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Events.Cancellable;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
public class PlayerSelectedSlotChangeEvent extends PlayerEvent implements Cancellable {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Player;
|
||||
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package com.loohp.limbo.Events;
|
||||
package com.loohp.limbo.Events.Status;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.loohp.limbo.Events.Event;
|
||||
import com.loohp.limbo.Server.ClientConnection;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
|
@ -42,6 +42,7 @@ public class ServerProperties {
|
|||
private boolean bungeecord;
|
||||
private int viewDistance;
|
||||
private double ticksPerSecond;
|
||||
private boolean handshakeVerbose;
|
||||
|
||||
Optional<BufferedImage> favicon;
|
||||
|
||||
|
|
@ -92,6 +93,7 @@ public class ServerProperties {
|
|||
bungeecord = Boolean.parseBoolean(prop.getProperty("bungeecord"));
|
||||
viewDistance = Integer.parseInt(prop.getProperty("view-distance"));
|
||||
ticksPerSecond = Double.parseDouble(prop.getProperty("ticks-per-second"));
|
||||
handshakeVerbose = Boolean.parseBoolean(prop.getProperty("handshake-verbose"));
|
||||
|
||||
File png = new File("server-icon.png");
|
||||
if (png.exists()) {
|
||||
|
|
@ -193,4 +195,8 @@ public class ServerProperties {
|
|||
return ticksPerSecond;
|
||||
}
|
||||
|
||||
public boolean handshakeVerboseEnabled() {
|
||||
return handshakeVerbose;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import com.loohp.limbo.Entity.DataWatcher.WatchableField;
|
|||
import com.loohp.limbo.Entity.DataWatcher.WatchableObjectType;
|
||||
import com.loohp.limbo.Entity.EntityType;
|
||||
import com.loohp.limbo.Entity.LivingEntity;
|
||||
import com.loohp.limbo.Events.PlayerChatEvent;
|
||||
import com.loohp.limbo.Events.PlayerTeleportEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerChatEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerTeleportEvent;
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Server.ClientConnection;
|
||||
import com.loohp.limbo.Server.Packets.PacketPlayOutChat;
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.loohp.limbo.DeclareCommands;
|
||||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.Events.PlayerJoinEvent;
|
||||
import com.loohp.limbo.Events.PlayerLoginEvent;
|
||||
import com.loohp.limbo.Events.PlayerMoveEvent;
|
||||
import com.loohp.limbo.Events.PlayerQuitEvent;
|
||||
import com.loohp.limbo.Events.PlayerSelectedSlotChangeEvent;
|
||||
import com.loohp.limbo.Events.StatusPingEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerJoinEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerLoginEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerMoveEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerQuitEvent;
|
||||
import com.loohp.limbo.Events.Player.PlayerSelectedSlotChangeEvent;
|
||||
import com.loohp.limbo.Events.Status.StatusPingEvent;
|
||||
import com.loohp.limbo.File.ServerProperties;
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
|
@ -63,6 +62,7 @@ import com.loohp.limbo.Server.Packets.PacketStatusOutPong;
|
|||
import com.loohp.limbo.Server.Packets.PacketStatusOutResponse;
|
||||
import com.loohp.limbo.Utils.CustomStringUtils;
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
import com.loohp.limbo.Utils.DeclareCommands;
|
||||
import com.loohp.limbo.Utils.GameMode;
|
||||
import com.loohp.limbo.Utils.MojangAPIUtils;
|
||||
import com.loohp.limbo.Utils.MojangAPIUtils.SkinResponse;
|
||||
|
|
@ -157,7 +157,7 @@ public class ClientConnection extends Thread {
|
|||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public void disconnectDuringLogin(BaseComponent[] reason) {
|
||||
private void disconnectDuringLogin(BaseComponent[] reason) {
|
||||
try {
|
||||
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(ComponentSerializer.toString(reason));
|
||||
sendPacket(packet);
|
||||
|
|
@ -205,88 +205,95 @@ public class ClientConnection extends Thread {
|
|||
UUID bungeeUUID = null;
|
||||
SkinResponse bungeeSkin = null;
|
||||
|
||||
switch (handshake.getHandshakeType()) {
|
||||
case STATUS:
|
||||
state = ClientState.STATUS;
|
||||
while (client_socket.isConnected()) {
|
||||
DataTypeIO.readVarInt(input);
|
||||
int packetId = DataTypeIO.readVarInt(input);
|
||||
Class<? extends Packet> packetType = Packet.getStatusIn().get(packetId);
|
||||
if (packetType == null) {
|
||||
//do nothing
|
||||
} else if (packetType.equals(PacketStatusInRequest.class)) {
|
||||
String str = client_socket.getInetAddress().getHostName() + ":" + client_socket.getPort();
|
||||
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Handshake Status has pinged");
|
||||
ServerProperties p = Limbo.getInstance().getServerProperties();
|
||||
StatusPingEvent event = Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
PacketStatusOutResponse packet = new PacketStatusOutResponse(Limbo.getInstance().buildServerListResponseJson(event.getVersion(), event.getProtocol(), event.getMotd(), event.getMaxPlayers(), event.getPlayersOnline(), event.getFavicon()));
|
||||
sendPacket(packet);
|
||||
} else if (packetType.equals(PacketStatusInPing.class)) {
|
||||
PacketStatusInPing ping = new PacketStatusInPing(input);
|
||||
PacketStatusOutPong packet = new PacketStatusOutPong(ping.getPayload());
|
||||
sendPacket(packet);
|
||||
break;
|
||||
try {
|
||||
switch (handshake.getHandshakeType()) {
|
||||
case STATUS:
|
||||
state = ClientState.STATUS;
|
||||
while (client_socket.isConnected()) {
|
||||
DataTypeIO.readVarInt(input);
|
||||
int packetId = DataTypeIO.readVarInt(input);
|
||||
Class<? extends Packet> packetType = Packet.getStatusIn().get(packetId);
|
||||
if (packetType == null) {
|
||||
//do nothing
|
||||
} else if (packetType.equals(PacketStatusInRequest.class)) {
|
||||
String str = client_socket.getInetAddress().getHostName() + ":" + client_socket.getPort();
|
||||
if (Limbo.getInstance().getServerProperties().handshakeVerboseEnabled()) {
|
||||
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Handshake Status has pinged");
|
||||
}
|
||||
ServerProperties p = Limbo.getInstance().getServerProperties();
|
||||
StatusPingEvent event = Limbo.getInstance().getEventsManager().callEvent(new StatusPingEvent(this, p.getVersionString(), p.getProtocol(), ComponentSerializer.parse(p.getMotdJson()), p.getMaxPlayers(), Limbo.getInstance().getPlayers().size(), p.getFavicon().orElse(null)));
|
||||
PacketStatusOutResponse packet = new PacketStatusOutResponse(Limbo.getInstance().buildServerListResponseJson(event.getVersion(), event.getProtocol(), event.getMotd(), event.getMaxPlayers(), event.getPlayersOnline(), event.getFavicon()));
|
||||
sendPacket(packet);
|
||||
} else if (packetType.equals(PacketStatusInPing.class)) {
|
||||
PacketStatusInPing ping = new PacketStatusInPing(input);
|
||||
PacketStatusOutPong packet = new PacketStatusOutPong(ping.getPayload());
|
||||
sendPacket(packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LOGIN:
|
||||
state = ClientState.LOGIN;
|
||||
|
||||
if (isBungeecord) {
|
||||
try {
|
||||
String[] data = bungeeForwarding.split("\\x00");
|
||||
//String host = data[0];
|
||||
String ip = data[1];
|
||||
|
||||
bungeeUUID = UUID.fromString(data[2].replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
||||
inetAddress = InetAddress.getByName(ip);
|
||||
|
||||
if (data.length > 3) {
|
||||
String skinJson = data[3];
|
||||
|
||||
String skin = skinJson.split("\"value\":\"")[1].split("\"")[0];
|
||||
String signature = skinJson.split("\"signature\":\"")[1].split("\"")[0];
|
||||
bungeeSkin = new SkinResponse(skin, signature);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Limbo.getInstance().getConsole().sendMessage("If you wish to use bungeecord's IP forwarding, please enable that in your bungeecord config.yml as well!");
|
||||
disconnectDuringLogin(new BaseComponent[] {new TextComponent(ChatColor.RED + "Please connect from the proxy!")});
|
||||
}
|
||||
}
|
||||
|
||||
while (client_socket.isConnected()) {
|
||||
int size = DataTypeIO.readVarInt(input);
|
||||
int packetId = DataTypeIO.readVarInt(input);
|
||||
Class<? extends Packet> packetType = Packet.getLoginIn().get(packetId);
|
||||
break;
|
||||
case LOGIN:
|
||||
state = ClientState.LOGIN;
|
||||
|
||||
if (packetType == null) {
|
||||
input.skipBytes(size - DataTypeIO.getVarIntLength(packetId));
|
||||
} else if (packetType.equals(PacketLoginInLoginStart.class)) {
|
||||
PacketLoginInLoginStart start = new PacketLoginInLoginStart(input);
|
||||
String username = start.getUsername();
|
||||
UUID uuid = isBungeecord ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
||||
if (isBungeecord) {
|
||||
try {
|
||||
String[] data = bungeeForwarding.split("\\x00");
|
||||
//String host = data[0];
|
||||
String ip = data[1];
|
||||
|
||||
bungeeUUID = UUID.fromString(data[2].replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
||||
inetAddress = InetAddress.getByName(ip);
|
||||
|
||||
if (data.length > 3) {
|
||||
String skinJson = data[3];
|
||||
|
||||
String skin = skinJson.split("\"value\":\"")[1].split("\"")[0];
|
||||
String signature = skinJson.split("\"signature\":\"")[1].split("\"")[0];
|
||||
bungeeSkin = new SkinResponse(skin, signature);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Limbo.getInstance().getConsole().sendMessage("If you wish to use bungeecord's IP forwarding, please enable that in your bungeecord config.yml as well!");
|
||||
disconnectDuringLogin(new BaseComponent[] {new TextComponent(ChatColor.RED + "Please connect from the proxy!")});
|
||||
}
|
||||
}
|
||||
|
||||
while (client_socket.isConnected()) {
|
||||
int size = DataTypeIO.readVarInt(input);
|
||||
int packetId = DataTypeIO.readVarInt(input);
|
||||
Class<? extends Packet> packetType = Packet.getLoginIn().get(packetId);
|
||||
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username);
|
||||
sendPacket(success);
|
||||
|
||||
state = ClientState.PLAY;
|
||||
|
||||
player = new Player(this, username, uuid, Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
|
||||
player.setSkinLayers((byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
|
||||
Limbo.getInstance().addPlayer(player);
|
||||
|
||||
break;
|
||||
} else {
|
||||
input.skipBytes(size - DataTypeIO.getVarIntLength(packetId));
|
||||
if (packetType == null) {
|
||||
input.skipBytes(size - DataTypeIO.getVarIntLength(packetId));
|
||||
} else if (packetType.equals(PacketLoginInLoginStart.class)) {
|
||||
PacketLoginInLoginStart start = new PacketLoginInLoginStart(input);
|
||||
String username = start.getUsername();
|
||||
UUID uuid = isBungeecord ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username);
|
||||
sendPacket(success);
|
||||
|
||||
state = ClientState.PLAY;
|
||||
|
||||
player = new Player(this, username, uuid, Limbo.getInstance().getNextEntityId(), Limbo.getInstance().getServerProperties().getWorldSpawn(), new PlayerInteractManager());
|
||||
player.setSkinLayers((byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
|
||||
Limbo.getInstance().addPlayer(player);
|
||||
|
||||
break;
|
||||
} else {
|
||||
input.skipBytes(size - DataTypeIO.getVarIntLength(packetId));
|
||||
}
|
||||
}
|
||||
|
||||
PlayerLoginEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false));
|
||||
if (event.isCancelled()) {
|
||||
disconnectDuringLogin(event.getCancelReason());
|
||||
}
|
||||
}
|
||||
|
||||
PlayerLoginEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false));
|
||||
if (event.isCancelled()) {
|
||||
disconnectDuringLogin(event.getCancelReason());
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client_socket.close();
|
||||
state = ClientState.DISCONNECTED;
|
||||
}
|
||||
|
||||
if (state == ClientState.PLAY) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class KeepAliveSender extends Thread {
|
|||
while (true) {
|
||||
try {
|
||||
for (ClientConnection client : Limbo.getInstance().getServerConnection().getClients()) {
|
||||
if (client.getClientState().equals(ClientState.PLAY)) {
|
||||
if (client.getClientState() != null && client.getClientState().equals(ClientState.PLAY)) {
|
||||
try {
|
||||
PacketPlayOutKeepAlive packet = new PacketPlayOutKeepAlive(random.nextLong());
|
||||
client.setLastKeepAlivePayLoad(packet.getPayload());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.loohp.limbo;
|
||||
package com.loohp.limbo.Utils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
|
@ -6,9 +6,9 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.Commands.CommandSender;
|
||||
import com.loohp.limbo.Server.Packets.PacketPlayOutDeclareCommands;
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
|
||||
public class DeclareCommands {
|
||||
|
||||
|
|
@ -34,6 +34,9 @@ view-distance=6
|
|||
#Ticks per second of the server
|
||||
ticks-per-second=5
|
||||
|
||||
#Should a message be printed to the console when a handshake occurs
|
||||
handshake-verbose=true
|
||||
|
||||
#Server list message in Json
|
||||
motd={"text":"","extra":[{"text":"Limbo Server!","color":"yellow"}]}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue