Initial commit

This commit is contained in:
dejanzegarac 2022-05-29 01:18:54 +02:00
parent 76a73ceae6
commit 59859a2fdf
19 changed files with 112 additions and 23 deletions

View File

@ -8,6 +8,7 @@
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/cryptomorin/XSeries/5.3.1/XSeries-5.3.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.12/lombok-1.18.12.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/moandjiezana/toml/toml4j/0.7.2/toml4j-0.7.2.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.google.code.gson:gson:2.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.1/gson-2.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.1/gson-2.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.1/gson-2.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.moandjiezana.toml:toml4j:0.7.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/moandjiezana/toml/toml4j/0.7.2/toml4j-0.7.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/moandjiezana/toml/toml4j/0.7.2/toml4j-0.7.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/moandjiezana/toml/toml4j/0.7.2/toml4j-0.7.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -17,6 +17,8 @@
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.6.4" level="project" />
<orderEntry type="library" name="Maven: com.moandjiezana.toml:toml4j:0.7.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.1" level="project" />
<orderEntry type="library" name="Maven: com.github.cryptomorin:XSeries:5.3.1" level="project" />
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.12" level="project" />
</component>

View File

@ -40,6 +40,11 @@
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>

View File

@ -1,5 +1,6 @@
package os.arcadiadevs.playerservers.hubcore;
import com.moandjiezana.toml.Toml;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@ -11,11 +12,16 @@ import os.arcadiadevs.playerservers.hubcore.events.HubEvents;
import os.arcadiadevs.playerservers.hubcore.events.JoinEvent;
import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
public class PSHubCore extends JavaPlugin {
public static Plugin PSH;
public static Toml multinode;
@SneakyThrows
@Override
@ -23,6 +29,7 @@ public class PSHubCore extends JavaPlugin {
PSH = this;
getConfig().options().copyDefaults(true);
saveConfig();
createMultiNodeConfig();
DataSource ds = new DataSource();
ds.registerDataSource();
@ -43,6 +50,31 @@ public class PSHubCore extends JavaPlugin {
Objects.requireNonNull(getCommand("servers")).setExecutor(new CommandManager());
}
private void createMultiNodeConfig() throws IOException {
if (!getConfig().getBoolean("multi-node")) {
return;
}
File configFile = new File(this.getDataFolder(), "multinode.toml");
//noinspection ResultOfMethodCallIgnored
getDataFolder().mkdirs();
if (configFile.createNewFile()) {
try (InputStream fis = getClass().getResourceAsStream("/multinode.toml"); FileOutputStream fos = new FileOutputStream(configFile)) {
byte[] buf = new byte[1024];
int i;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
} catch (Exception e) {
getLogger().info("[PlayerServers] Failed to load MultiNode file from Jar");
}
}
multinode = new Toml().read(new File(this.getDataFolder(), "multinode.toml"));
}
@Override
public void onDisable() {
super.onDisable();

View File

@ -38,7 +38,8 @@ public class DataBase {
rs.getString("SERVERID"),
rs.getString("PORT"),
rs.getString("NAME"),
rs.getString("PLAYERNAME"))
rs.getString("PLAYERNAME"),
rs.getString("NODE"))
);
}
return output;

View File

@ -2,18 +2,20 @@ package os.arcadiadevs.playerservers.hubcore.database.structures;
public class DBInfoStructure {
private String UUID;
private String ServerID;
private String Port;
private String ServerName;
private String PlayerName;
private final String UUID;
private final String ServerID;
private final String Port;
private final String ServerName;
private final String PlayerName;
private final String Node;
public DBInfoStructure(String UUID, String ServerID, String Port, String ServerName, String PlayerName) {
public DBInfoStructure(String UUID, String ServerID, String Port, String ServerName, String PlayerName, String node) {
this.UUID = UUID;
this.ServerID = ServerID;
this.Port = Port;
this.ServerName = ServerName;
this.PlayerName = PlayerName;
this.Node = node;
}
public String getPlayerName() {
@ -36,4 +38,8 @@ public class DBInfoStructure {
return UUID;
}
public String getNode() {
return Node;
}
}

View File

@ -7,11 +7,13 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
import os.arcadiadevs.playerservers.hubcore.database.DataBase;
import os.arcadiadevs.playerservers.hubcore.database.structures.DBInfoStructure;
import os.arcadiadevs.playerservers.hubcore.database.structures.PingInfoStructure;
import java.util.ArrayList;
import java.util.Map;
import static os.arcadiadevs.playerservers.hubcore.PSHubCore.PSH;
import static os.arcadiadevs.playerservers.hubcore.utils.ColorUtils.translate;
@ -19,23 +21,25 @@ import static os.arcadiadevs.playerservers.hubcore.utils.ColorUtils.translate;
public class GUIUtils {
public void openSelector(Player player) {
DataBase db = new DataBase();
PingUtil pu = new PingUtil();
final DataBase db = new DataBase();
final PingUtil pu = new PingUtil();
Inventory gui = Bukkit.createInventory(player, 9*6, ChatColor.GREEN + "Server Selector");
final Inventory gui = Bukkit.createInventory(player, 9*6, ChatColor.GREEN + "Server Selector");
final Map<String, Object> map = PSHubCore.multinode.getTable("servers").toMap();
Bukkit.getScheduler().runTaskAsynchronously(PSH, () -> {
for (DBInfoStructure is : db.getServersInfo()) {
ItemStack istack;
if (pu.isOnline("127.0.0.1", is.getPort())) {
final ItemStack istack;
if (pu.isOnline(PSH.getConfig().getBoolean("multi-node") ? map.get(is.getNode()).toString() : "127.0.0.1", is.getPort())) {
PingInfoStructure pus = pu.getData(Integer.parseInt(is.getPort()));
final PingInfoStructure pus = pu.getData(Integer.parseInt(is.getPort()));
final ArrayList<String> lore = new ArrayList<>();
istack = new ItemStack(XMaterial.EMERALD_BLOCK.parseMaterial());
ItemMeta ir = istack.getItemMeta();
final ItemMeta ir = istack.getItemMeta();
//noinspection ConstantConditions
ir.setDisplayName(translate("&a" + is.getPlayerName() + "'s server"));
ArrayList<String> lore = new ArrayList<>();
lore.add(translate("&cPort: &7" + is.getPort()));
lore.add(translate("&cUUID: &7" + is.getServerID().split("-")[0]));
lore.add(translate(String.format("&cOnline: &7%d/%d", pus.getOnline(), pus.getMax())));
@ -48,12 +52,12 @@ public class GUIUtils {
}
for (DBInfoStructure is : db.getServersInfo()) {
if (!pu.isOnline("127.0.0.1", is.getPort())) {
ItemStack istack = new ItemStack(XMaterial.REDSTONE_BLOCK.parseMaterial());
ItemMeta ir = istack.getItemMeta();
if (!pu.isOnline(PSH.getConfig().getBoolean("multi-node") ? map.get(is.getNode()).toString() : "127.0.0.1", is.getPort())) {
final ItemStack istack = new ItemStack(XMaterial.REDSTONE_BLOCK.parseMaterial());
final ItemMeta ir = istack.getItemMeta();
final ArrayList<String> lore = new ArrayList<>();
//noinspection ConstantConditions
ir.setDisplayName(translate("&a" + is.getPlayerName() + "'s server"));
ArrayList<String> lore = new ArrayList<>();
lore.add(translate("&cPort: &7" + is.getPort()));
lore.add(translate("&cUUID: &7" + is.getServerID().split("-")[0]));
ir.setLore(lore);

View File

@ -13,4 +13,7 @@ compass-description:
- "&7selector or to create your own one"
disable-weather: true
disable-damage: true
disable-damage: true
# EXPERIMENTAL
multi-node: false

View File

@ -0,0 +1,3 @@
# Please copy the content of multinode.toml from PSBungee here.
[servers]
example = "node1.example.com:25565"

View File

@ -1,6 +1,6 @@
name: PSHubCore
main: os.arcadiadevs.playerservers.hubcore.PSHubCore
version: 1.4.3
version: 1.4.4
author: OpenSource
softdepend: [PlaceholderAPI]

View File

@ -13,4 +13,7 @@ compass-description:
- "&7selector or to create your own one"
disable-weather: true
disable-damage: true
disable-damage: true
# EXPERIMENTAL
multi-node: false

View File

@ -0,0 +1,3 @@
# Please copy the content of multinode.toml from PSBungee here.
[servers]
example = "node1.example.com:25565"

View File

@ -1,6 +1,6 @@
name: PSHubCore
main: os.arcadiadevs.playerservers.hubcore.PSHubCore
version: 1.4.3
version: 1.4.4
author: OpenSource
softdepend: [PlaceholderAPI]