Fix X11 Error On Headless Servers With GUI Disabled (#573)

This commit is contained in:
Josh Shippam
2023-02-02 05:00:54 +00:00
committed by GitHub
parent fa7418929e
commit 209dae48a6
4 changed files with 214 additions and 208 deletions
@@ -112,7 +112,7 @@ public class GameEngine {
public static Trawler trawler = new Trawler(); public static Trawler trawler = new Trawler();
private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final static Lock lock = new ReentrantLock(); private final static Lock lock = new ReentrantLock();
public static ControlPanel panel = new ControlPanel(); public static ControlPanel panel;
static { static {
shutdownServer = false; shutdownServer = false;
@@ -209,6 +209,8 @@ public class GameEngine {
* Makes Visible Control Panel If Enabled * Makes Visible Control Panel If Enabled
*/ */
if(GameConstants.GUI_ENABLED) { if(GameConstants.GUI_ENABLED) {
ControlPanel panel = new ControlPanel();
panel.initComponents();
panel.setVisible(true); panel.setVisible(true);
System.out.println("Control Panel Enabled."); System.out.println("Control Panel Enabled.");
} }
@@ -51,6 +51,7 @@ import com.rs2.game.npcs.NpcHandler;
import com.rs2.game.npcs.impl.Pets; import com.rs2.game.npcs.impl.Pets;
import com.rs2.game.objects.ObjectsActions; import com.rs2.game.objects.ObjectsActions;
import com.rs2.game.shops.ShopAssistant; import com.rs2.game.shops.ShopAssistant;
import com.rs2.gui.ControlPanel;
import com.rs2.net.Packet; import com.rs2.net.Packet;
import com.rs2.net.Packet.Type; import com.rs2.net.Packet.Type;
import com.rs2.net.PacketSender; import com.rs2.net.PacketSender;
@@ -559,7 +560,8 @@ public abstract class Player {
if (session == null) { if (session == null) {
return; return;
} }
GameEngine.panel.removeEntity(playerName); if(GameConstants.GUI_ENABLED)
ControlPanel.removeEntity(playerName);
if (getCannon().hasCannon()) { if (getCannon().hasCannon()) {
getCannon().removeObject(cannonX, cannonY); getCannon().removeObject(cannonX, cannonY);
for(int i = 0; i < GameEngine.cannonsX.length; i++) { for(int i = 0; i < GameEngine.cannonsX.length; i++) {
@@ -27,7 +27,7 @@ public class ControlPanel extends JFrame {
public JButton EMPTY_BANK; public JButton EMPTY_BANK;
public JButton EMPTY_INVENTORY; public JButton EMPTY_INVENTORY;
public JList ENTITY_LIST; public JList ENTITY_LIST;
public DefaultListModel LIST_MODEL; public static DefaultListModel LIST_MODEL;
public DefaultListModel LIST_NPCS; public DefaultListModel LIST_NPCS;
public JMenuItem EXIT_ITEM; public JMenuItem EXIT_ITEM;
public JMenu FILE_MENU; public JMenu FILE_MENU;
@@ -96,15 +96,14 @@ public class ControlPanel extends JFrame {
public JScrollPane jScrollPane4; public JScrollPane jScrollPane4;
private PanelSettings settings = null; private PanelSettings settings = null;
public ControlPanel() { public ControlPanel() {
initComponents();
} }
public void addEntity(String name) { public static void addEntity(String name) {
this.LIST_MODEL.addElement(name); LIST_MODEL.addElement(name);
} }
public void removeEntity(String name) { public static void removeEntity(String name) {
this.LIST_MODEL.removeElement(name); LIST_MODEL.removeElement(name);
} }
public PanelSettings settings() { public PanelSettings settings() {
@@ -16,6 +16,7 @@ import com.rs2.game.items.impl.LightSources;
import com.rs2.game.players.Client; import com.rs2.game.players.Client;
import com.rs2.game.players.Player; import com.rs2.game.players.Player;
import com.rs2.game.players.PlayerHandler; import com.rs2.game.players.PlayerHandler;
import com.rs2.gui.ControlPanel;
import com.rs2.util.Misc; import com.rs2.util.Misc;
import com.rs2.world.Boundary; import com.rs2.world.Boundary;
import com.rs2.world.clip.Region; import com.rs2.world.clip.Region;
@@ -73,7 +74,9 @@ public class PacketSender {
} }
public PacketSender loginPlayer() { public PacketSender loginPlayer() {
GameEngine.panel.addEntity(player.playerName); if (GameConstants.GUI_ENABLED) {
ControlPanel.addEntity(player.playerName);
}
player.getPlayerAssistant().loginScreen(); player.getPlayerAssistant().loginScreen();
if (Connection.isNamedBanned(player.playerName)) { if (Connection.isNamedBanned(player.playerName)) {
player.logout(); player.logout();