reorganize classes for a better future

This commit is contained in:
LOOHP 2021-03-22 00:22:13 +08:00
parent e8a7d68e3b
commit 2d77a0e15c
18 changed files with 129 additions and 101 deletions

View File

@ -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>

View File

@ -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());

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package com.loohp.limbo.Events;
package com.loohp.limbo.Events.Player;
import com.loohp.limbo.Player.Player;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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,6 +205,7 @@ public class ClientConnection extends Thread {
UUID bungeeUUID = null;
SkinResponse bungeeSkin = null;
try {
switch (handshake.getHandshakeType()) {
case STATUS:
state = ClientState.STATUS;
@ -216,7 +217,9 @@ public class ClientConnection extends Thread {
//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()));
@ -288,6 +291,10 @@ public class ClientConnection extends Thread {
break;
}
} catch (Exception e) {
client_socket.close();
state = ClientState.DISCONNECTED;
}
if (state == ClientState.PLAY) {

View File

@ -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());

View File

@ -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 {

View File

@ -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"}]}