Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eh added a bit of docs before I make a bigger pr with way more docs #53

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion src/main/java/com/mattmalec/pterodactyl4j/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@

package com.mattmalec.pterodactyl4j;

/**
* Represents a format of data such as a {@link DataType#GB}
*/
public enum DataType {

// MB((byte) 0, 1, "Megabyte"),
// GB((byte) 1, 1024, "Gigabyte"),
// TB((byte) 2, 1048576, "Terabyte");

/**
* DataType format for Bytes
*/
B ((byte) 0, 1, "Byte"),
/**
* DataType format for Kilo-Bytes
Copy link
Contributor

@lokerhp lokerhp May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can’t this be just Kilobytes? (Same for gb / mb)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could yes, Just wanted to be clear, really just preference-based feel free to change it tho.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is your PR, you would have to be the one to change it

*/
KB((byte) 1, 1024, "Kilobyte"),
/**
* DataType format for Mega-Bytes
*/
MB((byte) 2, 1048576, "Megabyte"),
/**
* DataType format for Giga-Bytes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For stuff like this, you don't need to document each individual enum. They're pretty self-explanatory as it is.

*/
GB((byte) 3, 1_073_741_824, "Gigabyte"),
/**
* DataType format for Tera-Bytes
*/
TB((byte) 4, 1_099_511_627_776L, "Terabyte");

private final byte identifier;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/mattmalec/pterodactyl4j/UtilizationState.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,29 @@
package com.mattmalec.pterodactyl4j;

/**
* Represents a servers state.
* Represents a server's state.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

*/
public enum UtilizationState {

/**
* Represents when the server is offline
*/
OFFLINE,
/**
* Represents when the server is in the process of starting up
*/
STARTING,
/**
* Represents when the server is online
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this scenario, this makes sense to document the enum. I like what you did here :)

*/
RUNNING,
/**
* Represents when the server is shutting down
*/
STOPPING;

public static UtilizationState of(String s) {
for(UtilizationState state : values()) {
if(state.name().equalsIgnoreCase(s)) {
for (UtilizationState state : values()) {
if (state.name().equalsIgnoreCase(s)) {
return state;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,46 @@
import com.mattmalec.pterodactyl4j.PteroAction;
import com.mattmalec.pterodactyl4j.application.managers.UserAction;
import com.mattmalec.pterodactyl4j.entities.User;
import com.mattmalec.pterodactyl4j.utils.Relationed;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

/**
* Represents a user on a {@link ApplicationServer} server
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be explained better too. Also still confused on why these lines are spread out.

*/
public interface ApplicationUser extends User, ISnowflake {

String getFirstName();
String getLastName();
default String getFullName() {
return String.format("%s %s", getFirstName(), getLastName());
}
String getExternalId();
UUID getUUID();
boolean has2FA();
String getLanguage();
default Locale getLocale() {
return Locale.forLanguageTag(getLanguage());
}
boolean isRootAdmin();
PteroAction<List<ApplicationServer>> retrieveServers();
UserAction edit();
PteroAction<Void> delete();

@Override
String toString();
String getFirstName();

String getLastName();

default String getFullName() {
return String.format("%s %s", getFirstName(), getLastName());
}

String getExternalId();

UUID getUUID();

boolean has2FA();

String getLanguage();

default Locale getLocale() {
return Locale.forLanguageTag(getLanguage());
}

boolean isRootAdmin();

PteroAction<List<ApplicationServer>> retrieveServers();

UserAction edit();

PteroAction<Void> delete();

@Override
String toString();


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.List;
import java.util.Optional;

/**
* Represents a Pterodactyl {@link Nest}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be explained better too. I should have some comments around the review saying the same thing.

*/
public interface Nest extends ISnowflake {

String getUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.mattmalec.pterodactyl4j.PowerAction;
import com.mattmalec.pterodactyl4j.PteroAction;
import com.mattmalec.pterodactyl4j.PteroBuilder;
import com.mattmalec.pterodactyl4j.client.managers.*;
import com.mattmalec.pterodactyl4j.entities.Server;
import com.mattmalec.pterodactyl4j.requests.PaginationAction;
Expand All @@ -27,94 +28,130 @@
import java.util.Set;
import java.util.UUID;

/**
* Represents a {@link PteroClient}'s server
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would check how I did this with the ApplicationServer implementation. I'd ideally like to keep everything using the same conventions if possible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also kinda confused why this is all spaced out now.

* Use a {@link PteroClient} to retrieve a ptero information and servers
* To build a {@link PteroClient} use the {@link PteroBuilder#buildClient()} method.
*/
public interface ClientServer extends Server {

boolean isServerOwner();
long getInternalIdLong();
default String getInternalId() { return Long.toUnsignedString(getInternalIdLong()); }
SFTP getSFTPDetails();
String getInvocation();
Set<String> getEggFeatures();
ClientEgg getEgg();
String getNode();
boolean isSuspended();
boolean isInstalling();
boolean isTransferring();

ClientServerManager getManager();

PteroAction<Utilization> retrieveUtilization();
PteroAction<Void> setPower(PowerAction powerAction);

default PteroAction<Void> start() {
return setPower(PowerAction.START);
}

default PteroAction<Void> stop() {
return setPower(PowerAction.STOP);
}

default PteroAction<Void> restart() {
return setPower(PowerAction.RESTART);
}

default PteroAction<Void> kill() {
return setPower(PowerAction.KILL);
}

PteroAction<Void> sendCommand(String command);

WebSocketBuilder getWebSocketBuilder();

List<ClientSubuser> getSubusers();
PteroAction<ClientSubuser> retrieveSubuser(UUID uuid);
default PteroAction<ClientSubuser> retrieveSubuser(String uuid) {
return retrieveSubuser(UUID.fromString(uuid));
}
SubuserManager getSubuserManager();

PaginationAction<Backup> retrieveBackups();
PteroAction<Backup> retrieveBackup(UUID uuid);
default PteroAction<Backup> retrieveBackup(String uuid) {
return retrieveBackup(UUID.fromString(uuid));
}
BackupManager getBackupManager();

PteroAction<List<Schedule>> retrieveSchedules();
default PteroAction<Schedule> retrieveSchedule(long id) {
return retrieveSchedule(Long.toUnsignedString(id));
}
PteroAction<Schedule> retrieveSchedule(String id);
ScheduleManager getScheduleManager();

FileManager getFileManager();

default PteroAction<Directory> retrieveDirectory() {
return retrieveDirectory("/");
}
PteroAction<Directory> retrieveDirectory(Directory previousDirectory, Directory directory);
PteroAction<Directory> retrieveDirectory(String path);

PteroAction<List<ClientDatabase>> retrieveDatabases();
default PteroAction<Optional<ClientDatabase>> retrieveDatabaseById(String id) {
return retrieveDatabases().map(List::stream).map(stream -> stream.filter(db -> db.getId().equals(id)).findFirst());
}
default PteroAction<Optional<ClientDatabase>> retrieveDatabaseByName(String name, boolean caseSensitive) {
return retrieveDatabases().map(List::stream).map(stream -> stream.filter(db -> caseSensitive ?
db.getName().contains(name) : db.getName().toLowerCase().contains(name.toLowerCase())).findFirst());
}
ClientDatabaseManager getDatabaseManager();

List<ClientAllocation> getAllocations();
default ClientAllocation getPrimaryAllocation() {
return getAllocations().stream().filter(ClientAllocation::isDefault).findFirst().get();
}
default Optional<ClientAllocation> getAllocationByPort(int port) {
return getAllocations().stream().filter(allocation -> allocation.getPortInt() == port).findFirst();
}
default Optional<ClientAllocation> getAllocationById(long id) {
return getAllocations().stream().filter(allocation -> allocation.getIdLong() == id).findFirst();
}
ClientAllocationManager getAllocationManager();
boolean isServerOwner();

long getInternalIdLong();

default String getInternalId() {
return Long.toUnsignedString(getInternalIdLong());
}

SFTP getSFTPDetails();

String getInvocation();

Set<String> getEggFeatures();

ClientEgg getEgg();

String getNode();

boolean isSuspended();

boolean isInstalling();

boolean isTransferring();

ClientServerManager getManager();

PteroAction<Utilization> retrieveUtilization();

PteroAction<Void> setPower(PowerAction powerAction);

default PteroAction<Void> start() {
return setPower(PowerAction.START);
}

default PteroAction<Void> stop() {
return setPower(PowerAction.STOP);
}

default PteroAction<Void> restart() {
return setPower(PowerAction.RESTART);
}

default PteroAction<Void> kill() {
return setPower(PowerAction.KILL);
}

PteroAction<Void> sendCommand(String command);

WebSocketBuilder getWebSocketBuilder();

List<ClientSubuser> getSubusers();

PteroAction<ClientSubuser> retrieveSubuser(UUID uuid);

default PteroAction<ClientSubuser> retrieveSubuser(String uuid) {
return retrieveSubuser(UUID.fromString(uuid));
}

SubuserManager getSubuserManager();

PaginationAction<Backup> retrieveBackups();

PteroAction<Backup> retrieveBackup(UUID uuid);

default PteroAction<Backup> retrieveBackup(String uuid) {
return retrieveBackup(UUID.fromString(uuid));
}

BackupManager getBackupManager();

PteroAction<List<Schedule>> retrieveSchedules();

default PteroAction<Schedule> retrieveSchedule(long id) {
return retrieveSchedule(Long.toUnsignedString(id));
}

PteroAction<Schedule> retrieveSchedule(String id);

ScheduleManager getScheduleManager();

FileManager getFileManager();

default PteroAction<Directory> retrieveDirectory() {
return retrieveDirectory("/");
}

PteroAction<Directory> retrieveDirectory(Directory previousDirectory, Directory directory);

PteroAction<Directory> retrieveDirectory(String path);

PteroAction<List<ClientDatabase>> retrieveDatabases();

default PteroAction<Optional<ClientDatabase>> retrieveDatabaseById(String id) {
return retrieveDatabases().map(List::stream).map(stream -> stream.filter(db -> db.getId().equals(id)).findFirst());
}

default PteroAction<Optional<ClientDatabase>> retrieveDatabaseByName(String name, boolean caseSensitive) {
return retrieveDatabases().map(List::stream).map(stream -> stream.filter(db -> caseSensitive ?
db.getName().contains(name) : db.getName().toLowerCase().contains(name.toLowerCase())).findFirst());
}

ClientDatabaseManager getDatabaseManager();

List<ClientAllocation> getAllocations();

default ClientAllocation getPrimaryAllocation() {
return getAllocations().stream().filter(ClientAllocation::isDefault).findFirst().get();
}

default Optional<ClientAllocation> getAllocationByPort(int port) {
return getAllocations().stream().filter(allocation -> allocation.getPortInt() == port).findFirst();
}

default Optional<ClientAllocation> getAllocationById(long id) {
return getAllocations().stream().filter(allocation -> allocation.getIdLong() == id).findFirst();
}

ClientAllocationManager getAllocationManager();

}
Loading