Setup actions

This commit is contained in:
OpenSource 2022-12-08 18:02:45 +01:00
parent 48801fc1c5
commit 2f7e8e40be
8 changed files with 111 additions and 28 deletions

BIN
.DS_Store vendored

Binary file not shown.

22
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Java CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
- name: Build with Maven
run: mvn --batch-mode --update-snapshots package
- run: mkdir staging && cp target/*.jar staging
- uses: actions/upload-artifact@v3
with:
name: PSHubCore.jar
path: staging/PSHubCore.jar

View File

@ -10,12 +10,14 @@ import lombok.SneakyThrows;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import os.arcadiadevs.playerservers.hubcore.commands.CommandManager; import os.arcadiadevs.playerservers.hubcore.commands.CommandManager;
import os.arcadiadevs.playerservers.hubcore.controllers.NodesController; import os.arcadiadevs.playerservers.hubcore.controllers.NodesController;
import os.arcadiadevs.playerservers.hubcore.controllers.ServersController; import os.arcadiadevs.playerservers.hubcore.controllers.ServersController;
import os.arcadiadevs.playerservers.hubcore.events.ClickEvent; import os.arcadiadevs.playerservers.hubcore.events.ClickEvent;
import os.arcadiadevs.playerservers.hubcore.events.HubEvents; import os.arcadiadevs.playerservers.hubcore.events.HubEvents;
import os.arcadiadevs.playerservers.hubcore.events.JoinEvent; import os.arcadiadevs.playerservers.hubcore.events.JoinEvent;
import os.arcadiadevs.playerservers.hubcore.models.Allocation;
import os.arcadiadevs.playerservers.hubcore.models.Node; import os.arcadiadevs.playerservers.hubcore.models.Node;
import os.arcadiadevs.playerservers.hubcore.models.Server; import os.arcadiadevs.playerservers.hubcore.models.Server;
import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount; import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount;
@ -47,10 +49,11 @@ public class PsHubCore extends JavaPlugin {
extractFile("hibernate.cfg.xml"); extractFile("hibernate.cfg.xml");
sessionFactory = sessionFactory =
new org.hibernate.cfg.Configuration() new Configuration()
.configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml")) .configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml"))
.addAnnotatedClass(Server.class) .addAnnotatedClass(Server.class)
.addAnnotatedClass(Node.class) .addAnnotatedClass(Node.class)
.addAnnotatedClass(Allocation.class)
.buildSessionFactory(); .buildSessionFactory();
// Initialize the controllers // Initialize the controllers

View File

@ -65,7 +65,7 @@ public class PlayerMenuGui {
return; return;
} }
final var online = server.getStatus() == ServerStatus.ONLINE; final var online = server.getInfo() != null && server.getInfo().motd() != null && server.getStatus() == ServerStatus.ONLINE;
var lore = instance.getConfig().getStringList(online var lore = instance.getConfig().getStringList(online
? "gui.player-menu.menu.info.online.lore" ? "gui.player-menu.menu.info.online.lore"
@ -77,7 +77,7 @@ public class PlayerMenuGui {
.map(s -> s.replaceAll("%status%", online ? "&aOnline" : "&cOffline")) .map(s -> s.replaceAll("%status%", online ? "&aOnline" : "&cOffline"))
.map(s -> s.replaceAll("%players%", online ? server.getInfo().players() + "" : "0")) .map(s -> s.replaceAll("%players%", online ? server.getInfo().players() + "" : "0"))
.map(s -> s.replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0")) .map(s -> s.replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0"))
.map(s -> s.replaceAll("%port%", server.getPort() + "")) .map(s -> s.replaceAll("%port%", server.getDefaultAllocation().getPort() + ""))
.map(s -> s.replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline")) .map(s -> s.replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline"))
.map(s -> s.replaceAll("%node%", server.getNode().getName())) .map(s -> s.replaceAll("%node%", server.getNode().getName()))
.map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName())) .map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName()))

View File

@ -1,6 +1,7 @@
package os.arcadiadevs.playerservers.hubcore.guis; package os.arcadiadevs.playerservers.hubcore.guis;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.samjakob.spigui.buttons.SGButton; import com.samjakob.spigui.buttons.SGButton;
import com.samjakob.spigui.item.ItemBuilder; import com.samjakob.spigui.item.ItemBuilder;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,7 +47,7 @@ public class SelectorGui {
.map(s -> s.replaceAll("%status%", online ? "&aOnline" : "&cOffline")) .map(s -> s.replaceAll("%status%", online ? "&aOnline" : "&cOffline"))
.map(s -> s.replaceAll("%players%", online ? server.getInfo().players() + "" : "0")) .map(s -> s.replaceAll("%players%", online ? server.getInfo().players() + "" : "0"))
.map(s -> s.replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0")) .map(s -> s.replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0"))
.map(s -> s.replaceAll("%port%", server.getPort() + "")) .map(s -> s.replaceAll("%port%", server.getDefaultAllocation().getPort() + ""))
.map(s -> s.replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline")) .map(s -> s.replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline"))
.map(s -> s.replaceAll("%node%", server.getNode().getName())) .map(s -> s.replaceAll("%node%", server.getNode().getName()))
.map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName())) .map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName()))
@ -60,7 +61,7 @@ public class SelectorGui {
.replaceAll("%status%", online ? "&aOnline" : "&cOffline") .replaceAll("%status%", online ? "&aOnline" : "&cOffline")
.replaceAll("%players%", online ? server.getInfo().players() + "" : "0") .replaceAll("%players%", online ? server.getInfo().players() + "" : "0")
.replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0") .replaceAll("%maxplayers%", online ? server.getInfo().maxPlayers() + "" : "0")
.replaceAll("%port%", server.getPort() + "") .replaceAll("%port%", server.getDefaultAllocation().getPort() + "")
.replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline") .replaceAll("%motd%", online ? server.getInfo().motd() : "&cOffline")
.replaceAll("%node%", server.getNode().getName()) .replaceAll("%node%", server.getNode().getName())
.replaceAll("%owner%", server.getOfflinePlayer().getName()) .replaceAll("%owner%", server.getOfflinePlayer().getName())
@ -73,6 +74,7 @@ public class SelectorGui {
listener -> BungeeUtil.connectPlayer(player))); listener -> BungeeUtil.connectPlayer(player)));
}); });
XSound.BLOCK_NOTE_BLOCK_BASS.play(player);
player.openInventory(menu.getInventory()); player.openInventory(menu.getInventory());
} }

View File

@ -0,0 +1,47 @@
package os.arcadiadevs.playerservers.hubcore.models;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.net.InetSocketAddress;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "allocations")
@Getter
@Setter
public class Allocation {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "ip", nullable = false)
private String ip;
@Column(name = "port", nullable = false)
private Integer port;
@ManyToOne
@JoinColumn(name = "node")
private Node node;
@ManyToOne(optional = true)
@JoinColumn(name = "server_id", nullable = true)
private Server server;
public String getFullAddress() {
return this.ip + ":" + this.port;
}
public InetSocketAddress getInetAddress() {
return new InetSocketAddress(this.node.getIp(), this.port);
}
}

View File

@ -27,7 +27,7 @@ public class Node {
@Id @Id
@Column(name = "id") @Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id; private long id;
@Column(name = "name") @Column(name = "name")
private String name; private String name;
@ -38,14 +38,11 @@ public class Node {
@Column(name = "port") @Column(name = "port")
private int port; private int port;
@Column(name = "min_port") @Column(name = "max_online")
private int minPort; private Integer maxOnline;
@Column(name = "max_port") @Column(name = "pterodactyl")
private int maxPort; private boolean pterodactyl = false;
@Column(name = "max_servers")
private short maxServers;
@Column(name = "token") @Column(name = "token")
private String token; private String token;
@ -54,6 +51,10 @@ public class Node {
@OneToMany(mappedBy = "node", fetch = FetchType.EAGER) @OneToMany(mappedBy = "node", fetch = FetchType.EAGER)
private List<Server> servers; private List<Server> servers;
@Column(name = "allocations")
@OneToMany(mappedBy = "node", fetch = FetchType.EAGER)
private List<Allocation> allocations;
/** /**
* Get the full address of the server as ip:port. * Get the full address of the server as ip:port.
* *

View File

@ -2,13 +2,17 @@ package os.arcadiadevs.playerservers.hubcore.models;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import lombok.Getter; import lombok.Getter;
@ -36,20 +40,26 @@ public class Server {
@Column(name = "id") @Column(name = "id")
private String id; private String id;
@Column(name = "owner") @Column(name = "external_id")
private Long externalId = null;
@Column(name = "external_uuid")
private UUID externalUuid = null;
@Column(name = "owner", nullable = false)
private UUID owner; private UUID owner;
@Column(name = "port")
private Integer port;
@ManyToOne @ManyToOne
@JoinColumn(name = "node", nullable = false) @JoinColumn(name = "node")
private Node node; private Node node;
public String getFullAddress() { @Column(name = "allocations")
return (this.node.getIp() + ":" + this.port) @OneToMany(mappedBy = "id", fetch = FetchType.EAGER)
.replaceAll("localhost", "127.0.0.1"); private List<Allocation> allocations;
}
@JoinColumn(name = "default_allocation", referencedColumnName = "id")
@OneToOne
private Allocation defaultAllocation;
/** /**
* Gets the owner of the server as a OfflinePlayer. * Gets the owner of the server as a OfflinePlayer.
@ -79,7 +89,7 @@ public class Server {
* @return The InetSocketAddress * @return The InetSocketAddress
*/ */
public InetSocketAddress getInetAddress() { public InetSocketAddress getInetAddress() {
return new InetSocketAddress(this.node.getIp(), this.port); return defaultAllocation.getInetAddress();
} }
/** /**
@ -88,15 +98,13 @@ public class Server {
* @return The status of the server * @return The status of the server
*/ */
public ServerStatus getStatus() { public ServerStatus getStatus() {
final var address = node.getNumericAddress();
var status = ServerStatus.UNKNOWN; var status = ServerStatus.UNKNOWN;
try { try (Socket s = new Socket()) {
Socket s = new Socket(address, port); s.connect(getInetAddress(), 1000);
s.setSoTimeout(1000);
if (s.isConnected()) { if (s.isConnected()) {
status = ServerStatus.ONLINE; status = ServerStatus.ONLINE;
} }
s.close();
} catch (IOException ignored) { } catch (IOException ignored) {
status = ServerStatus.OFFLINE; status = ServerStatus.OFFLINE;
} }