Migrate from SQL classes to homeAPI package structure
This commit is contained in:
@@ -6,7 +6,17 @@
|
|||||||
|
|
||||||
<groupId>com.softwarerat</groupId>
|
<groupId>com.softwarerat</groupId>
|
||||||
<artifactId>HomesAPI</artifactId>
|
<artifactId>HomesAPI</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.3-SNAPSHOT</version>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>forgejo</id>
|
||||||
|
<name>Forgejo Maven</name>
|
||||||
|
<url>http://heimserver.local:36107/api/packages/minecraft/maven</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>18</maven.compiler.source>
|
<maven.compiler.source>18</maven.compiler.source>
|
||||||
@@ -32,5 +42,9 @@
|
|||||||
<id>papermc-repo</id>
|
<id>papermc-repo</id>
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>http://heimserver.local:36107/api/packages/minecraft/maven</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.softwarerat.SQL;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Homes {
|
|
||||||
|
|
||||||
|
|
||||||
private final Yaml yaml;
|
|
||||||
|
|
||||||
public Homes(Yaml yaml) {
|
|
||||||
this.yaml = yaml;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add or update a player home
|
|
||||||
public void addHome(String name, String uuid, String world, int x, int y, int z) {
|
|
||||||
String basePath = "homes." + name;
|
|
||||||
yaml.set(basePath + ".UUID", uuid);
|
|
||||||
yaml.set(basePath + ".World", world);
|
|
||||||
yaml.set(basePath + ".x", x);
|
|
||||||
yaml.set(basePath + ".y", y);
|
|
||||||
yaml.set(basePath + ".z", z);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a PlayerHome by name
|
|
||||||
public PlayerHome getHomeByName(String name) {
|
|
||||||
String basePath = "homes." + name;
|
|
||||||
if (!yaml.getConfig().contains(basePath)) return null;
|
|
||||||
|
|
||||||
String uuid = yaml.getString(basePath + ".UUID");
|
|
||||||
String world = yaml.getString(basePath + ".World");
|
|
||||||
int x = yaml.getInt(basePath + ".x");
|
|
||||||
int y = yaml.getInt(basePath + ".y");
|
|
||||||
int z = yaml.getInt(basePath + ".z");
|
|
||||||
|
|
||||||
return new PlayerHome(name, uuid, world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all homes for a player by UUID
|
|
||||||
public List<PlayerHome> getPlayerHomes(String uuid) {
|
|
||||||
List<PlayerHome> homes = new ArrayList<>();
|
|
||||||
if (!yaml.getConfig().contains("homes")) return homes;
|
|
||||||
|
|
||||||
for (String homeName : yaml.getConfig().getConfigurationSection("homes").getKeys(false)) {
|
|
||||||
String homeUUID = yaml.getString("homes." + homeName + ".UUID");
|
|
||||||
if (homeUUID != null && homeUUID.equals(uuid)) {
|
|
||||||
homes.add(getHomeByName(homeName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return homes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete a home by name
|
|
||||||
public void deleteHome(String name) {
|
|
||||||
if (yaml.getConfig().contains("homes." + name)) {
|
|
||||||
yaml.set("homes." + name, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a home exists
|
|
||||||
public boolean homeExists(String name) {
|
|
||||||
return yaml.getConfig().contains("homes." + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-4
@@ -1,15 +1,17 @@
|
|||||||
package com.softwarerat;
|
package com.softwarerat.homeAPI;
|
||||||
|
|
||||||
|
|
||||||
import com.softwarerat.SQL.Homes;
|
import com.softwarerat.homeAPI.SQL.Homes;
|
||||||
import com.softwarerat.SQL.Yaml;
|
import com.softwarerat.homeAPI.SQL.Yaml;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Main {
|
public class HomesAPI {
|
||||||
Yaml yaml;
|
Yaml yaml;
|
||||||
Homes homes;
|
Homes homes;
|
||||||
|
|
||||||
|
|
||||||
public void enableAPI(String path, String filename){
|
public void enableAPI(String path, String filename){
|
||||||
yaml = new Yaml(path, filename);
|
yaml = new Yaml(path, filename);
|
||||||
homes = new Homes(yaml);
|
homes = new Homes(yaml);
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.softwarerat.homeAPI.SQL;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Homes {
|
||||||
|
|
||||||
|
|
||||||
|
private final Yaml yaml;
|
||||||
|
|
||||||
|
public Homes(Yaml yaml) {
|
||||||
|
this.yaml = yaml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a specific home by name for a specific player.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Retrieves a home by name only.
|
||||||
|
* In this version, the Name is the unique identifier.
|
||||||
|
*/
|
||||||
|
public PlayerHome getHomeByName(String name) {
|
||||||
|
if (!yaml.getConfig().contains(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The path is now just "Name.key"
|
||||||
|
String uuid = yaml.getConfig().getString(name + ".uuid");
|
||||||
|
String world = yaml.getConfig().getString(name + ".world");
|
||||||
|
int x = yaml.getConfig().getInt(name + ".x");
|
||||||
|
int y = yaml.getConfig().getInt(name + ".y");
|
||||||
|
int z = yaml.getConfig().getInt(name + ".z");
|
||||||
|
|
||||||
|
return new PlayerHome(name, uuid, world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new home or updates an existing one.
|
||||||
|
*/
|
||||||
|
public void createNewHome(PlayerHome playerHome) {
|
||||||
|
String path = playerHome.getUUID() + "." + playerHome.getName();
|
||||||
|
|
||||||
|
yaml.getConfig().set(path + ".world", playerHome.getWorld());
|
||||||
|
yaml.getConfig().set(path + ".x", playerHome.getX());
|
||||||
|
yaml.getConfig().set(path + ".y", playerHome.getY());
|
||||||
|
yaml.getConfig().set(path + ".z", playerHome.getZ());
|
||||||
|
|
||||||
|
yaml.save(); // Write changes to disk
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a home from the YAML file.
|
||||||
|
*/
|
||||||
|
public void deleteHome(String uuid, String name) {
|
||||||
|
String path = uuid + "." + name;
|
||||||
|
if (yaml.getConfig().contains(path)) {
|
||||||
|
yaml.getConfig().set(path, null); // Setting to null removes the key
|
||||||
|
yaml.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all homes associated with a specific Player UUID.
|
||||||
|
*/
|
||||||
|
public List<PlayerHome> getPlayerHomes(String uuid) {
|
||||||
|
List<PlayerHome> homes = new ArrayList<>();
|
||||||
|
|
||||||
|
// Loop through every top-level key (every home name in the file)
|
||||||
|
for (String homeName : yaml.getConfig().getKeys(false)) {
|
||||||
|
String ownerUUID = yaml.getConfig().getString(homeName + ".uuid");
|
||||||
|
|
||||||
|
if (uuid.equals(ownerUUID)) {
|
||||||
|
homes.add(getHomeByName(homeName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return homes;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.softwarerat.SQL;
|
package com.softwarerat.homeAPI.SQL;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.softwarerat.SQL;
|
package com.softwarerat.homeAPI.SQL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user