mirror of
https://github.com/arcadiadevs/hubcore.git
synced 2024-11-21 06:05:21 +01:00
Setup actions
This commit is contained in:
parent
48801fc1c5
commit
2f7e8e40be
22
.github/workflows/main.yml
vendored
Normal file
22
.github/workflows/main.yml
vendored
Normal 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
|
@ -10,12 +10,14 @@ import lombok.SneakyThrows;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import os.arcadiadevs.playerservers.hubcore.commands.CommandManager;
|
||||
import os.arcadiadevs.playerservers.hubcore.controllers.NodesController;
|
||||
import os.arcadiadevs.playerservers.hubcore.controllers.ServersController;
|
||||
import os.arcadiadevs.playerservers.hubcore.events.ClickEvent;
|
||||
import os.arcadiadevs.playerservers.hubcore.events.HubEvents;
|
||||
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.Server;
|
||||
import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount;
|
||||
@ -47,10 +49,11 @@ public class PsHubCore extends JavaPlugin {
|
||||
extractFile("hibernate.cfg.xml");
|
||||
|
||||
sessionFactory =
|
||||
new org.hibernate.cfg.Configuration()
|
||||
new Configuration()
|
||||
.configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml"))
|
||||
.addAnnotatedClass(Server.class)
|
||||
.addAnnotatedClass(Node.class)
|
||||
.addAnnotatedClass(Allocation.class)
|
||||
.buildSessionFactory();
|
||||
|
||||
// Initialize the controllers
|
||||
|
@ -65,7 +65,7 @@ public class PlayerMenuGui {
|
||||
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
|
||||
? "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("%players%", online ? server.getInfo().players() + "" : "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("%node%", server.getNode().getName()))
|
||||
.map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName()))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package os.arcadiadevs.playerservers.hubcore.guis;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.cryptomorin.xseries.XSound;
|
||||
import com.samjakob.spigui.buttons.SGButton;
|
||||
import com.samjakob.spigui.item.ItemBuilder;
|
||||
import java.util.ArrayList;
|
||||
@ -46,7 +47,7 @@ public class SelectorGui {
|
||||
.map(s -> s.replaceAll("%status%", online ? "&aOnline" : "&cOffline"))
|
||||
.map(s -> s.replaceAll("%players%", online ? server.getInfo().players() + "" : "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("%node%", server.getNode().getName()))
|
||||
.map(s -> s.replaceAll("%owner%", server.getOfflinePlayer().getName()))
|
||||
@ -60,7 +61,7 @@ public class SelectorGui {
|
||||
.replaceAll("%status%", online ? "&aOnline" : "&cOffline")
|
||||
.replaceAll("%players%", online ? server.getInfo().players() + "" : "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("%node%", server.getNode().getName())
|
||||
.replaceAll("%owner%", server.getOfflinePlayer().getName())
|
||||
@ -73,6 +74,7 @@ public class SelectorGui {
|
||||
listener -> BungeeUtil.connectPlayer(player)));
|
||||
});
|
||||
|
||||
XSound.BLOCK_NOTE_BLOCK_BASS.play(player);
|
||||
player.openInventory(menu.getInventory());
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ public class Node {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
private long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
@ -38,14 +38,11 @@ public class Node {
|
||||
@Column(name = "port")
|
||||
private int port;
|
||||
|
||||
@Column(name = "min_port")
|
||||
private int minPort;
|
||||
@Column(name = "max_online")
|
||||
private Integer maxOnline;
|
||||
|
||||
@Column(name = "max_port")
|
||||
private int maxPort;
|
||||
|
||||
@Column(name = "max_servers")
|
||||
private short maxServers;
|
||||
@Column(name = "pterodactyl")
|
||||
private boolean pterodactyl = false;
|
||||
|
||||
@Column(name = "token")
|
||||
private String token;
|
||||
@ -54,6 +51,10 @@ public class Node {
|
||||
@OneToMany(mappedBy = "node", fetch = FetchType.EAGER)
|
||||
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.
|
||||
*
|
||||
|
@ -2,13 +2,17 @@ package os.arcadiadevs.playerservers.hubcore.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import lombok.Getter;
|
||||
@ -36,20 +40,26 @@ public class Server {
|
||||
@Column(name = "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;
|
||||
|
||||
@Column(name = "port")
|
||||
private Integer port;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "node", nullable = false)
|
||||
@JoinColumn(name = "node")
|
||||
private Node node;
|
||||
|
||||
public String getFullAddress() {
|
||||
return (this.node.getIp() + ":" + this.port)
|
||||
.replaceAll("localhost", "127.0.0.1");
|
||||
}
|
||||
@Column(name = "allocations")
|
||||
@OneToMany(mappedBy = "id", fetch = FetchType.EAGER)
|
||||
private List<Allocation> allocations;
|
||||
|
||||
@JoinColumn(name = "default_allocation", referencedColumnName = "id")
|
||||
@OneToOne
|
||||
private Allocation defaultAllocation;
|
||||
|
||||
/**
|
||||
* Gets the owner of the server as a OfflinePlayer.
|
||||
@ -79,7 +89,7 @@ public class Server {
|
||||
* @return The InetSocketAddress
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public ServerStatus getStatus() {
|
||||
final var address = node.getNumericAddress();
|
||||
|
||||
var status = ServerStatus.UNKNOWN;
|
||||
try {
|
||||
Socket s = new Socket(address, port);
|
||||
try (Socket s = new Socket()) {
|
||||
s.connect(getInetAddress(), 1000);
|
||||
s.setSoTimeout(1000);
|
||||
if (s.isConnected()) {
|
||||
status = ServerStatus.ONLINE;
|
||||
}
|
||||
s.close();
|
||||
} catch (IOException ignored) {
|
||||
status = ServerStatus.OFFLINE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user