From 2f7e8e40be510f623508c416d50c6f125ea9faa7 Mon Sep 17 00:00:00 2001 From: OpenSource Date: Thu, 8 Dec 2022 18:02:45 +0100 Subject: [PATCH] Setup actions --- .DS_Store | Bin 6148 -> 10244 bytes .github/workflows/main.yml | 22 ++++++++ .../playerservers/hubcore/PsHubCore.java | 5 +- .../hubcore/guis/PlayerMenuGui.java | 4 +- .../hubcore/guis/SelectorGui.java | 6 ++- .../hubcore/models/Allocation.java | 47 ++++++++++++++++++ .../playerservers/hubcore/models/Node.java | 17 ++++--- .../playerservers/hubcore/models/Server.java | 38 ++++++++------ 8 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 src/main/java/os/arcadiadevs/playerservers/hubcore/models/Allocation.java diff --git a/.DS_Store b/.DS_Store index 7dc50c89cc3a8d0ff5c301dcfa3122892b9c1c97..acf42742ebe7e61a677acd818360754831942dee 100644 GIT binary patch literal 10244 zcmeHMZ)_Ar6rZ;}=*g{1=THHE1*;YWQG?5lu`K;}?uE(fGkH_-1FX?X}1U6O_cA zWarJiH*aU=x4$>nHzkBXM1w$Bf!pw5I#&sJvqjudvsvsrT{1d zsCEmsW!69$@?_MLV_c#I3vgGI+!eeO1GqctL*BTkC&#$t?gYH#1H75R%TU0b9p4{v zhZBf$>DN92J_6GbV7YsMtRh21Cr(-Z4ljQ{*_O59@sweuP)9#K)q6R=^po~-d*+(< z-0-Bkf$Fp9N-Bs&3dBi`*g5ab@1}BwZad-dS0GdbX3VUlm9&cPPYhcl2}gAbc88kZ z%X&SQWu!`NHMK|AMv`)E%rYHSH?_R$pl383vae4!GuB9lRWLKQ>zm*PDpD~iE2E>4 z)^J;MXiZD_SaWD}{kk>Hq1H&-v11~g->`b)?&KjOYg&)6_2Q}GojznX?~m6fvE^;2 zn8=%kWe&07uGS`bk}iXm3@nOUza04OV+L#mas9H^1gz7oWuQVB2auV>Au7%| zM6@z!-}%>}ts5O(8Af2&wlZKNkqDwZ9odK3qOXB0L%wWJhFy$tx>VGc_Vjg$E}~SW z^z{!&NqKG&InkYSbj!5&Xn7lDQl4WYcebW2b5~wt_P(@b6tbqBlxxzekuDgjqqQ4G zLcdqD`yK6w!&-y3m3Lz9zgHP2rXe zcgDBwy!*oJ>N&C`&8zJz>b9OTv;oylYi33_hk8f!j59ol#55iKpswXbu|^2=m}*wL zuwY@Gtkf%uOJ02JgfEpFXn!H4A1>(5Q9g$fS}Icct$i6>*G?T=H8*&PIpc-$5++ag|>5p_OP1Qx<@d8J)h1Ul)7IH z^~`BYMt7_{ha{xzqI7`0u04~%H^~d@7VJ(a3Vs^hEb4e%;3wy&hWsU^v?02Je;gOq zhNv4YgoyZuhk^%Slys4O7&AF?l$<2blGEfB@;3R9oFnJSMe+^#mV8Gpk)O%$mTLX*%evuUyl*F*;5q zPQDV~CiB>(ZW-ZS>bl>0D(5hwlzM4#uot>A4J+LnAc9N~Gv|XoHQg3AR8d zbip#J{W*ONP~uS9R?lp;6MS2a39={q&)!-B4rCT&@I1T#FS_J? z6W-_K8zitWj$iKSyiD7* oM?Kvbm##bdx$Y?WZT@xtXFyi-^Z#&o@~xSl|Cesz{wMkWUxL=`kN^Mx delta 112 zcmZn(XfcprU|?W$DortDU=RQ@Ie-{MGjUE#6q~50$jG%ZU^gQp*Jd7p3yd36wOJOk ub8rYU162Tl05_0u1u5Q`_?>w&zltNsGzLZn1{M&_1ThXQwmF_>4l@Acix3F_ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e0eb6e0 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 \ No newline at end of file diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java index 3ed4a4f..e6400ee 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java @@ -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 diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/PlayerMenuGui.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/PlayerMenuGui.java index b47fa46..e8e5230 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/PlayerMenuGui.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/PlayerMenuGui.java @@ -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())) diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/SelectorGui.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/SelectorGui.java index 7845102..f39d362 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/SelectorGui.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/guis/SelectorGui.java @@ -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()); } diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Allocation.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Allocation.java new file mode 100644 index 0000000..1d49b72 --- /dev/null +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Allocation.java @@ -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); + } +} diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Node.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Node.java index 26770c9..7b8b9c9 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Node.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Node.java @@ -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 servers; + @Column(name = "allocations") + @OneToMany(mappedBy = "node", fetch = FetchType.EAGER) + private List allocations; + /** * Get the full address of the server as ip:port. * diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Server.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Server.java index 2b13c6b..78f92f8 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Server.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/models/Server.java @@ -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 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; }