Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/Validate-Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Validate Build

on:
# Trigger when a pull request is opened or reopened
pull_request:
types:
- opened
- reopened
# Trigger when a code review is submitted
pull_request_review:
types:
- submitted
# Allow manual runs
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'

- name: Build with Gradle
run: gradle build
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
// Apply the plugin
id 'com.github.johnrengelman.shadow' version '7.1.2'
id("xyz.jpenilla.run-paper") version "2.3.1"
}

Expand All @@ -17,10 +17,19 @@ repositories {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven{
url = "https://repo.aikar.co/content/groups/aikar/"
}

maven {
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")

implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
}

def targetJavaVersion = 21
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod_version=0.2.1
mod_version=0.2.2
325 changes: 325 additions & 0 deletions src/main/java/moe/sebiann/system/Classes/Home.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
package moe.sebiann.system.Classes;

import moe.sebiann.system.SystemHomes;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;

public class Home extends Location implements Serializable {

String name;
UUID owningPlayer;
boolean isPublic = false;

//<editor-fold desc="Constructor Overloading">
/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The UUID of the player who owns the home
* @param location The location where the home is
*/
public Home(String name, UUID owningPlayer, Location location) {
super(location);
this.name = name;
this.owningPlayer = owningPlayer;
}

/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The player who owns the home
* @param location The location where the home is
*/
public Home(String name, OfflinePlayer owningPlayer, Location location) {
super(location);
this.name = name;
this.owningPlayer = owningPlayer.getUniqueId();
}

/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The player who owns the home
* @param worldName The name of the world
* @param x The X-Coordinate
* @param y The Y-Coordinate
* @param z The Z-Coordinate
*/
public Home(String name, OfflinePlayer owningPlayer, String worldName, float x, float y, float z) {
super(worldName, x,y,z);
this.name = name;
this.owningPlayer = owningPlayer.getUniqueId();
}

/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The player UUID who owns the home
* @param worldName The name of the world
* @param x The X-Coordinate
* @param y The Y-Coordinate
* @param z The Z-Coordinate
*/
public Home(String name, UUID owningPlayer, String worldName, float x, float y, float z) {
super(worldName, x,y,z);
this.name = name;
this.owningPlayer = owningPlayer;
}

/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The player who owns the home
* @param worldName The name of the world
* @param x The X-Coordinate
* @param y The Y-Coordinate
* @param z The Z-Coordinate
* @param yaw The yaw
* @param pitch The pitch
*/
public Home(String name, OfflinePlayer owningPlayer, String worldName, float x, float y, float z, float yaw, float pitch) {
super(worldName, x,y,z, yaw, pitch);
this.name = name;
this.owningPlayer = owningPlayer.getUniqueId();
}

/**
* Creates a home Object
* @param name The name of the home
* @param owningPlayer The player UUID who owns the home
* @param worldName The name of the world
* @param x The X-Coordinate
* @param y The Y-Coordinate
* @param z The Z-Coordinate
* @param yaw The yaw
* @param pitch The pitch
*/
public Home(String name, UUID owningPlayer, String worldName, float x, float y, float z, float yaw, float pitch) {
super(worldName, x,y,z, yaw, pitch);
this.name = name;
this.owningPlayer = owningPlayer;
}
//</editor-fold>

//<editor-fold desc="Getters & Setters">
/**
* Gets the current home name
* @return The name of the home
*/
public String getHomeName() {
return name;
}

/**
* Sets the name of the home
* @param name New name of the home
*/
public void setHomeName(String name) {
this.name = name;
}

/**
* Gets who owns the home
* @return UUID of the player
*/
public UUID getOwner() {
return owningPlayer;
}

/**
* Gets if the home is public
* @return publicity of the home
*/
public boolean isPublic() {
return isPublic;
}

/**
* Sets the new publicity of this home
* @param isPublic whether the home is public or not
*/
public void setPublic(boolean isPublic) {
this.isPublic = isPublic;
}
//</editor-fold>

@Override
public String toString(){
return name;
}

/**
* Creates the YAML FileConfig of this class
* @return FileConfiguration of the YAML
*/
private FileConfiguration toYamlConfiguration(){
File homesFile = new File(SystemHomes.plugin.getDataFolder(), "homes.yml");

if (!homesFile.exists()) {
try {
if (homesFile.getParentFile().mkdirs()) {
SystemHomes.plugin.getLogger().info("Created plugin data directory.");
}
if (homesFile.createNewFile()) {
SystemHomes.plugin.getLogger().info("Created homes.yml file.");
}
} catch (IOException e) {
SystemHomes.plugin.getLogger().severe("Could not create homes.yml file!");
e.printStackTrace();
}
}

FileConfiguration config = YamlConfiguration.loadConfiguration(homesFile);
String path = "homes." + owningPlayer + "." + name;

config.set(path + ".world", world);
config.set(path + ".public", isPublic);
config.set(path + ".x", x);
config.set(path + ".y", y);
config.set(path + ".z", z);
config.set(path + ".yaw", yaw);
config.set(path + ".pitch", pitch);
return config;
}

/**
* @return the YAML string from this class
*/
public String toYamlString(){
return toYamlConfiguration().toString();
}

/**
* Adds the home to the homes.yml file
* @throws RuntimeException May throw a runtime exception if it can not write the file
*/
public void uploadHome(){
File homesFile = new File(SystemHomes.plugin.getDataFolder(), "homes.yml");
try {
toYamlConfiguration().save(homesFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Deletes a home from the homes.yml file
* @throws RuntimeException May throw a runtime exception if it can not write the file
*/
public void deleteHome() {
File homesFile = new File(SystemHomes.plugin.getDataFolder(), "homes.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(homesFile);
String path = "homes." + owningPlayer + "." + name;

if (config.contains(path)) {
config.set(path, null);

try {
config.save(homesFile);
} catch (IOException e) {
throw new RuntimeException("Could not save updated homes.yml file", e);
}
}
}

/**
* Gets the home object from a YAML config file
* @param config The YAML FileConfiguration
* @param pathPrefix the prefix of what to search
* @return Home object
*/
private static Home getHomeFromConfig(FileConfiguration config, String pathPrefix){
String[] pathSegments = pathPrefix.split("\\.");
String owningPlayer = pathSegments[pathSegments.length - 2];
String name = pathSegments[pathSegments.length - 1];

Home home = new Home(
name,
UUID.fromString(owningPlayer),
config.getString(pathPrefix + ".world"),
Float.parseFloat(config.getString(pathPrefix + ".x")),
Float.parseFloat(config.getString(pathPrefix + ".y")),
Float.parseFloat(config.getString(pathPrefix + ".z")),
Float.parseFloat(config.getString(pathPrefix + ".yaw")),
Float.parseFloat(config.getString(pathPrefix + ".pitch"))
);

home.setPublic(config.getBoolean(pathPrefix + ".public", false));
return home;
}

/**
* Gets the home object from a YAML string
* @param yamlString the YAML string of the object
* @return Home object
*/
public static Home fromYamlString(String yamlString) {
FileConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(yamlString));
String pathPrefix = "homes.";
return getHomeFromConfig(config, pathPrefix);
}

/**
* Gets the default home of the player
* @param owningPlayer The player whose home you want to get
* @return The home object
*/
public static Home getHome(UUID owningPlayer) {
return getHome(owningPlayer, "home");
}

/**
* Gets the specified home of the player
* @param owningPlayer The player whose home you want to get
* @param name The home name
* @return The home object
*/
public static Home getHome(UUID owningPlayer, String name) {
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(SystemHomes.plugin.getDataFolder(), "homes.yml"));
String pathPrefix = "homes." + owningPlayer + "." + name;

if (!config.contains(pathPrefix)) {
throw new IllegalArgumentException("Home '" + name + "' does not exist for player '" + owningPlayer + "' in the file.");
}

return getHomeFromConfig(config, pathPrefix);
}

public static boolean containsHome(String homePath){
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(SystemHomes.plugin.getDataFolder(), "homes.yml"));
return config.contains(homePath);
}

public static List<Home> getPlayerHomes(UUID owningPlayer){
List<Home> homes = new ArrayList<>();
File homesFile = new File(SystemHomes.plugin.getDataFolder(), "homes.yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(homesFile);

String playerPath = "homes." + owningPlayer.toString();

ConfigurationSection section = config.getConfigurationSection(playerPath);
if(section == null){
return homes;
}

Set<String> homeNames = section.getKeys(false);
for (String homeName : homeNames) {
String homePath = playerPath + "." + homeName;
Home home = getHomeFromConfig(config, homePath);
homes.add(home);
}

return homes;
}

}
Loading
Loading