├── .github ├── FUNDING.yml └── workflows │ └── formatting.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main └── java └── com └── mattmalec └── pterodactyl4j ├── ClientType.java ├── DataType.java ├── EnvironmentValue.java ├── P4JInfo.java ├── Permission.java ├── PowerAction.java ├── PteroAction.java ├── PteroBuilder.java ├── ServerStatus.java ├── UtilizationState.java ├── application ├── entities │ ├── ApplicationAllocation.java │ ├── ApplicationDatabase.java │ ├── ApplicationEgg.java │ ├── ApplicationServer.java │ ├── ApplicationUser.java │ ├── Container.java │ ├── DockerImage.java │ ├── ISnowflake.java │ ├── Location.java │ ├── Nest.java │ ├── Node.java │ ├── PteroApplication.java │ ├── Script.java │ └── impl │ │ ├── ApplicationAllocationImpl.java │ │ ├── ApplicationAllocationManagerImpl.java │ │ ├── ApplicationDatabaseCreationActionImpl.java │ │ ├── ApplicationDatabaseHostImpl.java │ │ ├── ApplicationDatabaseImpl.java │ │ ├── ApplicationDatabaseManagerImpl.java │ │ ├── ApplicationEggImpl.java │ │ ├── ApplicationEggVariableImpl.java │ │ ├── ApplicationServerImpl.java │ │ ├── ApplicationUserImpl.java │ │ ├── ContainerImpl.java │ │ ├── CreateAllocationImpl.java │ │ ├── CreateLocationImpl.java │ │ ├── CreateNodeImpl.java │ │ ├── CreateServerImpl.java │ │ ├── CreateUserImpl.java │ │ ├── DockerImageImpl.java │ │ ├── EditAllocationImpl.java │ │ ├── EditLocationImpl.java │ │ ├── EditNodeImpl.java │ │ ├── EditUserImpl.java │ │ ├── LocationImpl.java │ │ ├── LocationManagerImpl.java │ │ ├── NestImpl.java │ │ ├── NodeConfigurationImpl.java │ │ ├── NodeImpl.java │ │ ├── NodeManagerImpl.java │ │ ├── PteroApplicationImpl.java │ │ ├── ScriptImpl.java │ │ ├── ServerBuildManagerImpl.java │ │ ├── ServerDetailManagerImpl.java │ │ ├── ServerStartupManagerImpl.java │ │ └── UserManagerImpl.java └── managers │ ├── AllocationAction.java │ ├── ApplicationAllocationManager.java │ ├── ApplicationDatabaseCreationAction.java │ ├── ApplicationDatabaseManager.java │ ├── LocationAction.java │ ├── LocationManager.java │ ├── NodeAction.java │ ├── NodeManager.java │ ├── ServerBuildManager.java │ ├── ServerController.java │ ├── ServerCreationAction.java │ ├── ServerDetailManager.java │ ├── ServerManager.java │ ├── ServerStartupManager.java │ ├── UserAction.java │ └── UserManager.java ├── client ├── entities │ ├── APIKey.java │ ├── Account.java │ ├── Backup.java │ ├── ClientAllocation.java │ ├── ClientDatabase.java │ ├── ClientEgg.java │ ├── ClientServer.java │ ├── ClientSubuser.java │ ├── Cron.java │ ├── Directory.java │ ├── DownloadableFile.java │ ├── File.java │ ├── GenericFile.java │ ├── PteroClient.java │ ├── SFTP.java │ ├── Schedule.java │ ├── Utilization.java │ └── impl │ │ ├── APIKeyImpl.java │ │ ├── AccountImpl.java │ │ ├── BackupImpl.java │ │ ├── BackupManagerImpl.java │ │ ├── CachedDirectoryImpl.java │ │ ├── ClientAllocationImpl.java │ │ ├── ClientAllocationManagerImpl.java │ │ ├── ClientDatabaseCreationActionImpl.java │ │ ├── ClientDatabaseHostImpl.java │ │ ├── ClientDatabaseImpl.java │ │ ├── ClientDatabaseManagerImpl.java │ │ ├── ClientEggImpl.java │ │ ├── ClientEggVariableImpl.java │ │ ├── ClientServerImpl.java │ │ ├── ClientSubuserImpl.java │ │ ├── CompressActionImpl.java │ │ ├── CreateAPIKeyImpl.java │ │ ├── CreateBackupImpl.java │ │ ├── CreateDirectoryActionImpl.java │ │ ├── CreateScheduleImpl.java │ │ ├── CreateScheduleTaskImpl.java │ │ ├── CreateSubuserImpl.java │ │ ├── CronImpl.java │ │ ├── DecompressActionImpl.java │ │ ├── DeleteActionImpl.java │ │ ├── DirectoryImpl.java │ │ ├── EditScheduleImpl.java │ │ ├── EditScheduleTaskImpl.java │ │ ├── EditSubuserImpl.java │ │ ├── FileImpl.java │ │ ├── FileManagerImpl.java │ │ ├── GenericFileImpl.java │ │ ├── GenericRootFileImpl.java │ │ ├── PteroClientImpl.java │ │ ├── RenameActionImpl.java │ │ ├── RootDirectoryImpl.java │ │ ├── SFTPImpl.java │ │ ├── ScheduleImpl.java │ │ ├── ScheduleManagerImpl.java │ │ ├── ScheduleTaskImpl.java │ │ ├── ScheduleTaskManagerImpl.java │ │ ├── SubuserManagerImpl.java │ │ ├── UploadFileActionImpl.java │ │ └── UtilizationImpl.java ├── managers │ ├── APIKeyAction.java │ ├── AccountManager.java │ ├── BackupAction.java │ ├── BackupManager.java │ ├── ClientAllocationManager.java │ ├── ClientDatabaseCreationAction.java │ ├── ClientDatabaseManager.java │ ├── ClientServerManager.java │ ├── CompressAction.java │ ├── CreateDirectoryAction.java │ ├── DeleteAction.java │ ├── FileManager.java │ ├── RenameAction.java │ ├── ScheduleAction.java │ ├── ScheduleManager.java │ ├── ScheduleTaskAction.java │ ├── ScheduleTaskManager.java │ ├── SubuserAction.java │ ├── SubuserCreationAction.java │ ├── SubuserManager.java │ ├── UploadFileAction.java │ ├── WebSocketBuilder.java │ └── WebSocketManager.java └── ws │ ├── WebSocketAction.java │ ├── WebSocketClient.java │ ├── events │ ├── AuthSuccessEvent.java │ ├── BackupCompletedEvent.java │ ├── Event.java │ ├── StatsUpdateEvent.java │ ├── StatusUpdateEvent.java │ ├── connection │ │ ├── ConnectedEvent.java │ │ ├── ConnectionEvent.java │ │ ├── DisconnectedEvent.java │ │ ├── DisconnectingEvent.java │ │ ├── DisconnectionEvent.java │ │ └── FailureEvent.java │ ├── error │ │ ├── DaemonErrorEvent.java │ │ └── JWTErrorEvent.java │ ├── install │ │ ├── InstallCompletedEvent.java │ │ ├── InstallEvent.java │ │ └── InstallStartedEvent.java │ ├── output │ │ ├── ConsoleOutputEvent.java │ │ ├── DaemonMessageEvent.java │ │ ├── InstallOutputEvent.java │ │ └── OutputEvent.java │ ├── token │ │ ├── TokenEvent.java │ │ ├── TokenExpiredEvent.java │ │ └── TokenExpiringEvent.java │ └── transfer │ │ ├── TransferLogEvent.java │ │ └── TransferStatusEvent.java │ ├── handle │ ├── AuthSuccessHandler.java │ ├── BackupCompletedHandler.java │ ├── ClientSocketHandler.java │ ├── ConsoleOuputHandler.java │ ├── DaemonErrorHandler.java │ ├── DaemonMessageHandler.java │ ├── InstallCompletedHandler.java │ ├── InstallOuputHandler.java │ ├── InstallStartedHandler.java │ ├── JWTErrorHandler.java │ ├── StatsHandler.java │ ├── StatusHandler.java │ ├── TokenExpiredHandler.java │ ├── TokenExpiringHandler.java │ ├── TransferLogHandler.java │ └── TransferStatusHandler.java │ └── hooks │ ├── ClientSocketListener.java │ ├── ClientSocketListenerAdapter.java │ ├── IClientListenerManager.java │ └── InterfacedClientListenerManager.java ├── entities ├── Allocation.java ├── Database.java ├── Egg.java ├── FeatureLimit.java ├── IPermissionHolder.java ├── Limit.java ├── P4J.java ├── Server.java ├── User.java └── impl │ ├── DatabasePasswordImpl.java │ ├── FeatureLimitImpl.java │ ├── LimitImpl.java │ └── P4JImpl.java ├── exceptions ├── FileUploadException.java ├── HttpException.java ├── IllegalActionException.java ├── LoginException.java ├── MissingActionException.java ├── NotFoundException.java ├── PteroException.java ├── RateLimitedException.java └── ServerException.java ├── requests ├── CompletedPaginationAction.java ├── CompletedPteroAction.java ├── DeferredPteroAction.java ├── Method.java ├── PaginationAction.java ├── PteroActionImpl.java ├── RateLimiter.java ├── Request.java ├── RequestFuture.java ├── Requester.java ├── Response.java ├── Route.java └── action │ ├── AbstractAllocationAction.java │ ├── AbstractDatabaseAction.java │ ├── AbstractLocationAction.java │ ├── AbstractManagerBase.java │ ├── AbstractNodeAction.java │ ├── AbstractScheduleAction.java │ ├── AbstractScheduleTaskAction.java │ ├── AbstractSubuserAction.java │ ├── AbstractUserAction.java │ ├── impl │ ├── PaginationActionImpl.java │ └── PaginationResponseImpl.java │ └── operator │ ├── DelayPteroAction.java │ ├── FlatMapErrorPteroAction.java │ ├── FlatMapPteroAction.java │ ├── MapErrorPteroAction.java │ ├── MapPteroAction.java │ └── PteroActionOperator.java └── utils ├── AwaitableClientListener.java ├── BufferedRequestBody.java ├── Checks.java ├── CronUtils.java ├── ExceptionUtils.java ├── LockUtils.java ├── NamedThreadFactory.java ├── P4JLogger.java ├── PaginatedEntity.java ├── Procedure.java ├── Relationed.java ├── SimpleLogger.java ├── StreamUtils.java └── config ├── EndpointConfig.java ├── SessionConfig.java └── ThreadingConfig.java /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [ mattmalec ] 2 | custom: [ "https://paypal.me/mattmalec" ] -------------------------------------------------------------------------------- /.github/workflows/formatting.yml: -------------------------------------------------------------------------------- 1 | name: Gradle 2 | on: pull_request 3 | jobs: 4 | formatting: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | with: 9 | fetch-depth: 0 10 | 11 | - uses: actions/setup-java@v3 12 | with: 13 | distribution: corretto 14 | java-version: 8 15 | 16 | - name: Setup Gradle 17 | uses: gradle/gradle-build-action@v2 18 | 19 | - name: Validate code 20 | run: ./gradlew spotlessCheck 21 | 22 | build: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v3 26 | with: 27 | fetch-depth: 0 28 | 29 | - uses: actions/setup-java@v3 30 | with: 31 | distribution: corretto 32 | java-version: 8 33 | 34 | - name: Setup Gradle 35 | uses: gradle/gradle-build-action@v2 36 | 37 | - name: Build code 38 | run: ./gradlew build 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.ipr 18 | /out/ 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | 27 | ### Custom ### 28 | /logs/ 29 | /src/test/java/ 30 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattmalec/Pterodactyl4J/1b8825fcf5d365734bd6db7bf5df7c930d0cc72b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Pterodactyl4J' 2 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/ClientType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | public enum ClientType { 20 | NONE(""), 21 | OWNER("owner"), 22 | ADMIN_ALL("admin-all"), 23 | ADMIN("admin"); 24 | 25 | private final String type; 26 | 27 | ClientType(String type) { 28 | this.type = type; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/DataType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | public enum DataType { 20 | 21 | // MB((byte) 0, 1, "Megabyte"), 22 | // GB((byte) 1, 1024, "Gigabyte"), 23 | // TB((byte) 2, 1048576, "Terabyte"); 24 | 25 | B((byte) 0, 1, "Byte"), 26 | KB((byte) 1, 1024, "Kilobyte"), 27 | MB((byte) 2, 1048576, "Megabyte"), 28 | GB((byte) 3, 1_073_741_824, "Gigabyte"), 29 | TB((byte) 4, 1_099_511_627_776L, "Terabyte"); 30 | 31 | private final byte identifier; 32 | private final long byteValue; 33 | private final String friendlyName; 34 | 35 | DataType(byte identifier, long byteValue, String friendlyName) { 36 | this.identifier = identifier; 37 | this.byteValue = byteValue; 38 | this.friendlyName = friendlyName; 39 | } 40 | 41 | public static DataType getByIdentifier(byte identifier) { 42 | for (DataType dataType : values()) { 43 | if (dataType.getIdentifier() == identifier) { 44 | return dataType; 45 | } 46 | } 47 | return null; 48 | } 49 | 50 | public byte getIdentifier() { 51 | return identifier; 52 | } 53 | 54 | public long getByteValue() { 55 | return byteValue; 56 | } 57 | 58 | public long getMbValue() { 59 | return byteValue / MB.getByteValue(); 60 | } 61 | 62 | public String getFriendlyName() { 63 | return friendlyName; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/P4JInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | /** 20 | * Contains information to this specific build of P4J. 21 | */ 22 | public class P4JInfo { 23 | 24 | public static final String VERSION_MAJOR = "@MAJOR@"; 25 | public static final String VERSION_MINOR = "@MINOR@"; 26 | public static final String VERSION_BUILD = "@BUILD@"; 27 | 28 | public static final String VERSION = VERSION_MAJOR.startsWith("@") 29 | ? "DEV" 30 | : String.format("%s.%s_%s", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/PowerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | /** 20 | * Represents an action that can be sent to modify its power status. 21 | * 22 | * @see com.mattmalec.pterodactyl4j.client.entities.ClientServer#setPower(PowerAction) 23 | */ 24 | public enum PowerAction { 25 | START, 26 | STOP, 27 | RESTART, 28 | KILL 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/ServerStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationServer; 20 | 21 | /** 22 | * Represents the status of an {@link com.mattmalec.pterodactyl4j.application.entities.ApplicationServer ApplicationServer} 23 | * 24 | * @see ApplicationServer#getStatus() 25 | */ 26 | public enum ServerStatus { 27 | INSTALLING, 28 | INSTALL_FAILED, 29 | SUSPENDED, 30 | RESTORING_BACKUP, 31 | UNKNOWN 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/UtilizationState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j; 18 | 19 | /** 20 | * Represents a servers state. 21 | */ 22 | public enum UtilizationState { 23 | OFFLINE, 24 | STARTING, 25 | RUNNING, 26 | STOPPING; 27 | 28 | public static UtilizationState of(String s) { 29 | for (UtilizationState state : values()) { 30 | if (state.name().equalsIgnoreCase(s)) { 31 | return state; 32 | } 33 | } 34 | return UtilizationState.OFFLINE; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/ApplicationUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.managers.UserAction; 21 | import com.mattmalec.pterodactyl4j.entities.User; 22 | import java.util.List; 23 | import java.util.Locale; 24 | import java.util.UUID; 25 | 26 | public interface ApplicationUser extends User, ISnowflake { 27 | 28 | String getFirstName(); 29 | 30 | String getLastName(); 31 | 32 | default String getFullName() { 33 | return String.format("%s %s", getFirstName(), getLastName()); 34 | } 35 | 36 | String getExternalId(); 37 | 38 | UUID getUUID(); 39 | 40 | boolean has2FA(); 41 | 42 | String getLanguage(); 43 | 44 | default Locale getLocale() { 45 | return Locale.forLanguageTag(getLanguage()); 46 | } 47 | 48 | boolean isRootAdmin(); 49 | 50 | PteroAction> retrieveServers(); 51 | 52 | UserAction edit(); 53 | 54 | PteroAction delete(); 55 | 56 | @Override 57 | String toString(); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/DockerImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | public interface DockerImage { 20 | String getName(); 21 | 22 | String getImage(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/ISnowflake.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | import java.time.OffsetDateTime; 20 | 21 | /** 22 | * Marks a snowflake entity. Snowflake entities are ones that have an id that uniquely identifies them. 23 | */ 24 | public interface ISnowflake { 25 | 26 | /** 27 | * The Snowflake id of this entity. This is unique to every entity and will never change. 28 | * 29 | * @return Never-null String containing the id. 30 | */ 31 | default String getId() { 32 | return Long.toUnsignedString(getIdLong()); 33 | } 34 | 35 | /** 36 | * The Snowflake id of this entity. This is unique to every entity and will never change. 37 | * 38 | * @return Long containing the id. 39 | */ 40 | long getIdLong(); 41 | 42 | /** 43 | * The time this entity was created. 44 | * 45 | * @return OffsetDateTime - Time this entity was created at. 46 | * 47 | * @see #getUpdatedDate() 48 | */ 49 | OffsetDateTime getCreationDate(); 50 | 51 | /** 52 | * The time this entity was updated. 53 | * 54 | * @return OffsetDateTime - Time this entity was last updated at. 55 | * 56 | * @see #getCreationDate() 57 | */ 58 | OffsetDateTime getUpdatedDate(); 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/Location.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.managers.LocationAction; 21 | import java.util.List; 22 | 23 | /** 24 | * Represents a Pterodactyl {@link com.mattmalec.pterodactyl4j.application.entities.Location Location}. 25 | * This should contain all information provided from the Pterodactyl instance about a Location. 26 | */ 27 | public interface Location extends ISnowflake { 28 | 29 | String getShortCode(); 30 | 31 | String getDescription(); 32 | 33 | PteroAction> getNodes(); 34 | 35 | PteroAction> getServers(); 36 | 37 | LocationAction edit(); 38 | 39 | PteroAction delete(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/Nest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import java.util.List; 21 | import java.util.Optional; 22 | 23 | public interface Nest extends ISnowflake { 24 | 25 | String getUUID(); 26 | 27 | String getAuthor(); 28 | 29 | String getName(); 30 | 31 | String getDescription(); 32 | 33 | PteroAction> retrieveEggs(); 34 | 35 | Optional> getServers(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/Script.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities; 18 | 19 | public interface Script { 20 | 21 | boolean isPrivileged(); 22 | 23 | String getInstall(); 24 | 25 | String getEntry(); 26 | 27 | String getContainer(); 28 | 29 | String getExtends(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateAllocationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.Node; 20 | import com.mattmalec.pterodactyl4j.requests.Route; 21 | import com.mattmalec.pterodactyl4j.requests.action.AbstractAllocationAction; 22 | import com.mattmalec.pterodactyl4j.utils.Checks; 23 | import okhttp3.RequestBody; 24 | import org.json.JSONObject; 25 | 26 | public class CreateAllocationImpl extends AbstractAllocationAction { 27 | 28 | public CreateAllocationImpl(PteroApplicationImpl impl, Node node) { 29 | super(impl, Route.Nodes.CREATE_ALLOCATION.compile(node.getId())); 30 | } 31 | 32 | @Override 33 | protected RequestBody finalizeData() { 34 | JSONObject json = new JSONObject(); 35 | Checks.notBlank(ip, "IP"); 36 | if (alias != null) Checks.check(alias.length() <= 191, "Allocation alias cannot be longer than 191 characters"); 37 | 38 | json.put("ip", ip); 39 | json.put("alias", alias); 40 | json.put("ports", portSet); 41 | return getRequestBody(json); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateLocationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.requests.Route; 20 | import com.mattmalec.pterodactyl4j.requests.action.AbstractLocationAction; 21 | import com.mattmalec.pterodactyl4j.utils.Checks; 22 | import okhttp3.RequestBody; 23 | import org.json.JSONObject; 24 | 25 | public class CreateLocationImpl extends AbstractLocationAction { 26 | 27 | CreateLocationImpl(PteroApplicationImpl impl) { 28 | super(impl, Route.Locations.CREATE_LOCATION.compile()); 29 | } 30 | 31 | @Override 32 | protected RequestBody finalizeData() { 33 | Checks.notBlank(this.shortCode, "Shortcode"); 34 | Checks.notBlank(this.description, "Description"); 35 | JSONObject json = new JSONObject(); 36 | json.put("short", this.shortCode); 37 | json.put("long", this.description); 38 | return getRequestBody(json); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateUserImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.requests.Route; 20 | import com.mattmalec.pterodactyl4j.requests.action.AbstractUserAction; 21 | import com.mattmalec.pterodactyl4j.utils.Checks; 22 | import okhttp3.RequestBody; 23 | import org.json.JSONObject; 24 | 25 | public class CreateUserImpl extends AbstractUserAction { 26 | 27 | public CreateUserImpl(PteroApplicationImpl impl) { 28 | super(impl, Route.Users.CREATE_USER.compile()); 29 | } 30 | 31 | @Override 32 | protected RequestBody finalizeData() { 33 | Checks.notBlank(userName, "Username"); 34 | Checks.notBlank(email, "Email"); 35 | Checks.notBlank(firstName, "First name"); 36 | Checks.notBlank(lastName, "Last name"); 37 | JSONObject json = new JSONObject(); 38 | json.put("username", userName); 39 | json.put("email", email); 40 | json.put("first_name", firstName); 41 | json.put("last_name", lastName); 42 | json.put("password", password); 43 | return getRequestBody(json); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/DockerImageImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.DockerImage; 20 | 21 | public class DockerImageImpl implements DockerImage { 22 | private final String name; 23 | private final String image; 24 | 25 | public DockerImageImpl(String name, String image) { 26 | this.name = name; 27 | this.image = image; 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | @Override 36 | public String getImage() { 37 | return image; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditLocationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.Location; 20 | import com.mattmalec.pterodactyl4j.requests.Route; 21 | import com.mattmalec.pterodactyl4j.requests.action.AbstractLocationAction; 22 | import okhttp3.RequestBody; 23 | import org.json.JSONObject; 24 | 25 | public class EditLocationImpl extends AbstractLocationAction { 26 | 27 | private final Location location; 28 | 29 | EditLocationImpl(Location location, PteroApplicationImpl impl) { 30 | super(impl, Route.Locations.EDIT_LOCATION.compile(location.getId())); 31 | this.location = location; 32 | } 33 | 34 | @Override 35 | protected RequestBody finalizeData() { 36 | JSONObject json = new JSONObject(); 37 | json.put("short", shortCode == null ? location.getShortCode() : shortCode); 38 | json.put("long", description == null ? location.getDescription() : description); 39 | return getRequestBody(json); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditUserImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationUser; 20 | import com.mattmalec.pterodactyl4j.requests.Route; 21 | import com.mattmalec.pterodactyl4j.requests.action.AbstractUserAction; 22 | import okhttp3.RequestBody; 23 | import org.json.JSONObject; 24 | 25 | public class EditUserImpl extends AbstractUserAction { 26 | 27 | private final ApplicationUser user; 28 | 29 | public EditUserImpl(ApplicationUser user, PteroApplicationImpl impl) { 30 | super(impl, Route.Users.EDIT_USER.compile(user.getId())); 31 | this.user = user; 32 | } 33 | 34 | @Override 35 | protected RequestBody finalizeData() { 36 | JSONObject json = new JSONObject(); 37 | json.put("username", userName == null ? user.getUserName() : userName); 38 | json.put("email", email == null ? user.getEmail() : email); 39 | json.put("first_name", firstName == null ? user.getFirstName() : firstName); 40 | json.put("last_name", lastName == null ? user.getLastName() : lastName); 41 | json.put("password", password); 42 | return getRequestBody(json); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/LocationManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.Location; 21 | import com.mattmalec.pterodactyl4j.application.managers.LocationAction; 22 | import com.mattmalec.pterodactyl4j.application.managers.LocationManager; 23 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 24 | import com.mattmalec.pterodactyl4j.requests.Route; 25 | 26 | public class LocationManagerImpl implements LocationManager { 27 | 28 | private final PteroApplicationImpl impl; 29 | 30 | public LocationManagerImpl(PteroApplicationImpl impl) { 31 | this.impl = impl; 32 | } 33 | 34 | @Override 35 | public LocationAction createLocation() { 36 | return new CreateLocationImpl(impl); 37 | } 38 | 39 | @Override 40 | public LocationAction editLocation(Location location) { 41 | return new EditLocationImpl(location, impl); 42 | } 43 | 44 | @Override 45 | public PteroAction deleteLocation(Location location) { 46 | return PteroActionImpl.onRequestExecute( 47 | impl.getP4J(), Route.Locations.DELETE_LOCATION.compile(location.getId())); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/NodeManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.Node; 21 | import com.mattmalec.pterodactyl4j.application.managers.NodeAction; 22 | import com.mattmalec.pterodactyl4j.application.managers.NodeManager; 23 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 24 | import com.mattmalec.pterodactyl4j.requests.Route; 25 | 26 | public class NodeManagerImpl implements NodeManager { 27 | 28 | private final PteroApplicationImpl impl; 29 | 30 | public NodeManagerImpl(PteroApplicationImpl impl) { 31 | this.impl = impl; 32 | } 33 | 34 | @Override 35 | public NodeAction createNode() { 36 | return new CreateNodeImpl(impl); 37 | } 38 | 39 | @Override 40 | public NodeAction editNode(Node node) { 41 | return new EditNodeImpl(impl, node); 42 | } 43 | 44 | @Override 45 | public PteroAction deleteNode(Node node) { 46 | return PteroActionImpl.onRequestExecute(impl.getP4J(), Route.Nodes.DELETE_NODE.compile(node.getId())); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/ScriptImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.Script; 20 | import org.json.JSONObject; 21 | 22 | public class ScriptImpl implements Script { 23 | 24 | private final JSONObject json; 25 | 26 | public ScriptImpl(JSONObject json) { 27 | this.json = json; 28 | } 29 | 30 | @Override 31 | public boolean isPrivileged() { 32 | return json.getBoolean("privileged"); 33 | } 34 | 35 | @Override 36 | public String getInstall() { 37 | return json.getString("install"); 38 | } 39 | 40 | @Override 41 | public String getEntry() { 42 | return json.getString("entry"); 43 | } 44 | 45 | @Override 46 | public String getContainer() { 47 | return json.getString("container"); 48 | } 49 | 50 | @Override 51 | public String getExtends() { 52 | return json.getString("extends"); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return json.toString(4); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/UserManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationUser; 21 | import com.mattmalec.pterodactyl4j.application.managers.UserAction; 22 | import com.mattmalec.pterodactyl4j.application.managers.UserManager; 23 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 24 | import com.mattmalec.pterodactyl4j.requests.Route; 25 | 26 | public class UserManagerImpl implements UserManager { 27 | 28 | private final PteroApplicationImpl impl; 29 | 30 | public UserManagerImpl(PteroApplicationImpl impl) { 31 | this.impl = impl; 32 | } 33 | 34 | @Override 35 | public UserAction createUser() { 36 | return new CreateUserImpl(impl); 37 | } 38 | 39 | @Override 40 | public UserAction editUser(ApplicationUser user) { 41 | return new EditUserImpl(user, impl); 42 | } 43 | 44 | @Override 45 | public PteroAction deleteUser(ApplicationUser user) { 46 | return PteroActionImpl.onRequestExecute(impl.getP4J(), Route.Users.DELETE_USER.compile(user.getId())); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/AllocationAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | 21 | public interface AllocationAction extends PteroAction { 22 | 23 | AllocationAction setIP(String ip); 24 | 25 | AllocationAction setAlias(String alias); 26 | 27 | AllocationAction setPorts(String... ports); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/ApplicationAllocationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationAllocation; 21 | 22 | public interface ApplicationAllocationManager { 23 | 24 | AllocationAction createAllocation(); 25 | 26 | PteroAction deleteAllocation(ApplicationAllocation allocation); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/ApplicationDatabaseManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationDatabase; 21 | 22 | public interface ApplicationDatabaseManager { 23 | 24 | ApplicationDatabaseCreationAction createDatabase(); 25 | 26 | PteroAction resetPassword(ApplicationDatabase database); 27 | 28 | PteroAction deleteDatabase(ApplicationDatabase database); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/LocationAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.Location; 21 | 22 | public interface LocationAction extends PteroAction { 23 | 24 | LocationAction setShortCode(String shortCode); 25 | 26 | LocationAction setDescription(String description); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/LocationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.Location; 21 | 22 | public interface LocationManager { 23 | 24 | LocationAction createLocation(); 25 | 26 | LocationAction editLocation(Location location); 27 | 28 | PteroAction deleteLocation(Location location); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/application/managers/NodeManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.application.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.application.entities.Node; 21 | 22 | public interface NodeManager { 23 | 24 | NodeAction createNode(); 25 | 26 | NodeAction editNode(Node node); 27 | 28 | PteroAction deleteNode(Node node); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/APIKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import java.time.OffsetDateTime; 21 | import java.util.Set; 22 | 23 | public interface APIKey { 24 | 25 | String getIdentifier(); 26 | 27 | String getDescription(); 28 | 29 | Set getAllowedIps(); 30 | 31 | OffsetDateTime getLastUsedDate(); 32 | 33 | OffsetDateTime getCreationDate(); 34 | 35 | String getToken(); 36 | 37 | PteroAction delete(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.managers.APIKeyAction; 21 | import com.mattmalec.pterodactyl4j.client.managers.AccountManager; 22 | import com.mattmalec.pterodactyl4j.entities.User; 23 | import java.util.List; 24 | import java.util.Locale; 25 | import java.util.Optional; 26 | import java.util.stream.Stream; 27 | 28 | public interface Account extends User { 29 | 30 | String getFirstName(); 31 | 32 | String getLastName(); 33 | 34 | default String getFullName() { 35 | return String.format("%s %s", getFirstName(), getLastName()); 36 | } 37 | 38 | long getId(); 39 | 40 | boolean isRootAdmin(); 41 | 42 | String getLanguage(); 43 | 44 | default Locale getLocale() { 45 | return Locale.forLanguageTag(getLanguage()); 46 | } 47 | 48 | PteroAction> retrieveAPIKeys(); 49 | 50 | default PteroAction> retrieveAPIKeyByIdentifier(String identifier) { 51 | return retrieveAPIKeys() 52 | .map(List::stream) 53 | .map(stream -> stream.filter(key -> key.getIdentifier().equals(identifier))) 54 | .map(Stream::findFirst); 55 | } 56 | 57 | APIKeyAction createAPIKey(); 58 | 59 | AccountManager getManager(); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/Backup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.DataType; 20 | import com.mattmalec.pterodactyl4j.PteroAction; 21 | import java.time.OffsetDateTime; 22 | import java.util.List; 23 | import java.util.UUID; 24 | 25 | public interface Backup { 26 | 27 | UUID getUUID(); 28 | 29 | String getName(); 30 | 31 | String getChecksum(); 32 | 33 | boolean isSuccessful(); 34 | 35 | boolean isLocked(); 36 | 37 | long getSize(); 38 | 39 | default String getSizeFormatted(DataType dataType) { 40 | return String.format("%.2f %s", getSize() / (dataType.getMbValue() * Math.pow(2, 20)), dataType.name()); 41 | } 42 | 43 | List getIgnoredFiles(); 44 | 45 | PteroAction retrieveDownloadUrl(); 46 | 47 | OffsetDateTime getTimeCompleted(); 48 | 49 | OffsetDateTime getTimeCreated(); 50 | 51 | PteroAction toggleLock(); 52 | 53 | PteroAction restore(); 54 | 55 | PteroAction delete(); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/ClientDatabase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.entities.Database; 21 | 22 | public interface ClientDatabase extends Database { 23 | 24 | String getId(); 25 | 26 | Database.DatabaseHost getHost(); 27 | 28 | PteroAction resetPassword(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/ClientSubuser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.entities.IPermissionHolder; 20 | import com.mattmalec.pterodactyl4j.entities.User; 21 | import java.time.OffsetDateTime; 22 | import java.util.UUID; 23 | 24 | public interface ClientSubuser extends User, IPermissionHolder { 25 | 26 | String getImage(); 27 | 28 | boolean has2FA(); 29 | 30 | UUID getUUID(); 31 | 32 | OffsetDateTime getCreationDate(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/Cron.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | public interface Cron { 20 | 21 | String getDayOfWeek(); 22 | 23 | String getDayOfMonth(); 24 | 25 | String getHour(); 26 | 27 | String getMinute(); 28 | 29 | String getMonth(); 30 | 31 | String getExpression(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/File.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | 21 | public interface File extends GenericFile { 22 | 23 | PteroAction retrieveContent(); 24 | 25 | PteroAction retrieveDownload(); 26 | 27 | PteroAction write(String content); 28 | 29 | PteroAction copy(); 30 | 31 | PteroAction decompress(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/GenericFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.DataType; 20 | import com.mattmalec.pterodactyl4j.PteroAction; 21 | import java.nio.file.attribute.PosixFilePermission; 22 | import java.time.OffsetDateTime; 23 | import java.util.EnumSet; 24 | 25 | public interface GenericFile { 26 | 27 | String getName(); 28 | 29 | String getPath(); 30 | 31 | long getSizeBytes(); 32 | 33 | default double getSize(DataType dataType) { 34 | return getSizeBytes() / (double) dataType.getByteValue(); 35 | } 36 | 37 | default String getSizeFormatted(DataType dataType) { 38 | return String.format("%.2f %s", getSize(dataType), dataType.name()); 39 | } 40 | 41 | GenericFile.Permission getPermissions(); 42 | 43 | boolean isFile(); 44 | 45 | boolean isSymlink(); 46 | 47 | String getMimeType(); 48 | 49 | OffsetDateTime getCreationDate(); 50 | 51 | OffsetDateTime getModifedDate(); 52 | 53 | PteroAction rename(String name); 54 | 55 | PteroAction delete(); 56 | 57 | interface Permission { 58 | int getBits(); 59 | 60 | EnumSet getPosixPermissions(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/SFTP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities; 18 | 19 | public interface SFTP { 20 | 21 | String getIP(); 22 | 23 | int getPort(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/CachedDirectoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.GenericFile; 21 | import java.util.List; 22 | import org.json.JSONObject; 23 | 24 | public class CachedDirectoryImpl extends DirectoryImpl { 25 | 26 | public CachedDirectoryImpl(JSONObject json, GenericFile genericFile, ClientServer server) { 27 | super(json, genericFile, server); 28 | } 29 | 30 | @Override 31 | public List getFiles() { 32 | throw new UnsupportedOperationException("You need to Directory#into(Directory) this object to get the files"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/ClientDatabaseHostImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientDatabase; 20 | import org.json.JSONObject; 21 | 22 | public class ClientDatabaseHostImpl implements ClientDatabase.DatabaseHost { 23 | 24 | private final JSONObject json; 25 | 26 | public ClientDatabaseHostImpl(JSONObject json) { 27 | this.json = json; 28 | } 29 | 30 | @Override 31 | public String getAddress() { 32 | return json.getString("address"); 33 | } 34 | 35 | @Override 36 | public int getPort() { 37 | return json.getInt("port"); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return json.toString(4); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/ClientEggImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientEgg; 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.List; 23 | import java.util.UUID; 24 | import org.json.JSONObject; 25 | 26 | public class ClientEggImpl implements ClientEgg { 27 | 28 | private final JSONObject json; 29 | private final JSONObject variables; 30 | 31 | public ClientEggImpl(JSONObject json, JSONObject variables) { 32 | this.json = json.getJSONObject("attributes"); 33 | this.variables = variables; 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return json.getString("name"); 39 | } 40 | 41 | @Override 42 | public UUID getUUID() { 43 | return UUID.fromString(json.getString("uuid")); 44 | } 45 | 46 | @Override 47 | public List getVariables() { 48 | List variables = new ArrayList<>(); 49 | for (Object o : this.variables.getJSONArray("data")) { 50 | JSONObject variable = new JSONObject(o.toString()); 51 | variables.add(new ClientEggVariableImpl(variable)); 52 | } 53 | return Collections.unmodifiableList(variables); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/ClientEggVariableImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.EnvironmentValue; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientEgg; 21 | import org.json.JSONObject; 22 | 23 | public class ClientEggVariableImpl implements ClientEgg.EggVariable { 24 | 25 | private final JSONObject json; 26 | 27 | public ClientEggVariableImpl(JSONObject json) { 28 | this.json = json.getJSONObject("attributes"); 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return json.getString("name"); 34 | } 35 | 36 | @Override 37 | public String getDescription() { 38 | return json.getString("description"); 39 | } 40 | 41 | @Override 42 | public String getEnvironmentVariable() { 43 | return json.getString("env_variable"); 44 | } 45 | 46 | @Override 47 | public EnvironmentValue getDefaultValue() { 48 | return EnvironmentValue.of(json.get("default_value")); 49 | } 50 | 51 | @Override 52 | public EnvironmentValue getServerValue() { 53 | return EnvironmentValue.of(json.get("server_value")); 54 | } 55 | 56 | @Override 57 | public boolean isEditable() { 58 | return json.getBoolean("is_editable"); 59 | } 60 | 61 | @Override 62 | public String getRules() { 63 | return json.getString("rules"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/CreateScheduleTaskImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 21 | import com.mattmalec.pterodactyl4j.requests.Route; 22 | import com.mattmalec.pterodactyl4j.requests.action.AbstractScheduleTaskAction; 23 | 24 | public class CreateScheduleTaskImpl extends AbstractScheduleTaskAction { 25 | 26 | public CreateScheduleTaskImpl(ClientServer server, Schedule schedule, PteroClientImpl impl) { 27 | super( 28 | impl, 29 | schedule, 30 | Route.Schedules.CREATE_TASK.compile(server.getUUID().toString(), schedule.getId())); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/DecompressActionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.File; 21 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 22 | import com.mattmalec.pterodactyl4j.requests.Route; 23 | import com.mattmalec.pterodactyl4j.utils.Checks; 24 | import okhttp3.RequestBody; 25 | import org.json.JSONObject; 26 | 27 | public class DecompressActionImpl extends PteroActionImpl { 28 | 29 | private final File compressedFile; 30 | 31 | public DecompressActionImpl(ClientServer server, File compressedFile, PteroClientImpl impl) { 32 | super(impl.getP4J(), Route.Files.DECOMPRESS_FILE.compile(server.getIdentifier())); 33 | this.compressedFile = compressedFile; 34 | } 35 | 36 | @Override 37 | protected RequestBody finalizeData() { 38 | Checks.notNull(compressedFile, "Compressed File"); 39 | 40 | JSONObject json = new JSONObject().put("file", compressedFile.getPath()).put("root", "/"); 41 | return getRequestBody(json); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/EditScheduleTaskImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 21 | import com.mattmalec.pterodactyl4j.requests.Route; 22 | import com.mattmalec.pterodactyl4j.requests.action.AbstractScheduleTaskAction; 23 | 24 | public class EditScheduleTaskImpl extends AbstractScheduleTaskAction { 25 | 26 | public EditScheduleTaskImpl( 27 | ClientServer server, Schedule schedule, Schedule.ScheduleTask task, PteroClientImpl impl) { 28 | super( 29 | impl, 30 | schedule, 31 | Route.Schedules.UPDATE_TASK.compile(server.getUUID().toString(), schedule.getId(), task.getId())); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/EditSubuserImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser; 21 | import com.mattmalec.pterodactyl4j.requests.Route; 22 | import com.mattmalec.pterodactyl4j.requests.action.AbstractSubuserAction; 23 | import com.mattmalec.pterodactyl4j.utils.Checks; 24 | import java.util.stream.Collectors; 25 | import okhttp3.RequestBody; 26 | import org.json.JSONObject; 27 | 28 | public class EditSubuserImpl extends AbstractSubuserAction { 29 | 30 | public EditSubuserImpl(ClientServer server, ClientSubuser subuser, PteroClientImpl impl) { 31 | super( 32 | impl, 33 | Route.Subusers.UPDATE_SUBUSER.compile( 34 | server.getUUID().toString(), subuser.getUUID().toString())); 35 | } 36 | 37 | @Override 38 | protected RequestBody finalizeData() { 39 | Checks.notEmpty(this.permissions, "Permissions"); 40 | JSONObject json = new JSONObject() 41 | .put( 42 | "permissions", 43 | permissions.stream() 44 | .map(permission -> permission.getRaw()) 45 | .collect(Collectors.toList())); 46 | return getRequestBody(json); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/RootDirectoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import org.json.JSONObject; 21 | 22 | public class RootDirectoryImpl extends DirectoryImpl { 23 | 24 | public RootDirectoryImpl(JSONObject json, String rootPath, ClientServer server) { 25 | super(json, new GenericRootFileImpl(rootPath), server); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/entities/impl/SFTPImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.SFTP; 20 | import org.json.JSONObject; 21 | 22 | public class SFTPImpl implements SFTP { 23 | 24 | private final JSONObject json; 25 | 26 | public SFTPImpl(JSONObject json) { 27 | this.json = json; 28 | } 29 | 30 | @Override 31 | public String getIP() { 32 | return json.getString("ip"); 33 | } 34 | 35 | @Override 36 | public int getPort() { 37 | return json.getInt("port"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/APIKeyAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.APIKey; 21 | 22 | public interface APIKeyAction extends PteroAction { 23 | 24 | APIKeyAction setDescription(String description); 25 | 26 | APIKeyAction setAllowedIps(String... ips); 27 | 28 | APIKeyAction addAllowedIps(String... ips); 29 | 30 | APIKeyAction addAllowedIp(String ip); 31 | 32 | APIKeyAction removeAllowedIp(String ip); 33 | 34 | APIKeyAction removeAllowedIps(String... ips); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/BackupAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Backup; 21 | import java.util.List; 22 | 23 | public interface BackupAction extends PteroAction { 24 | 25 | BackupAction setName(String name); 26 | 27 | BackupAction setIgnoredFiles(List files); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/BackupManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Backup; 21 | 22 | public interface BackupManager { 23 | 24 | BackupAction createBackup(); 25 | 26 | PteroAction retrieveDownloadUrl(Backup backup); 27 | 28 | PteroAction restoreBackup(Backup backup); 29 | 30 | PteroAction toggleLock(Backup backup); 31 | 32 | PteroAction deleteBackup(Backup backup); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ClientAllocationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientAllocation; 21 | 22 | public interface ClientAllocationManager { 23 | 24 | PteroAction setNote(ClientAllocation allocation, String note); 25 | 26 | PteroAction unassignAllocation(ClientAllocation allocation); 27 | 28 | PteroAction assignAllocation(); 29 | 30 | PteroAction setPrimary(ClientAllocation allocation); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ClientDatabaseManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientDatabase; 21 | 22 | public interface ClientDatabaseManager { 23 | 24 | ClientDatabaseCreationAction createDatabase(); 25 | 26 | PteroAction resetPassword(ClientDatabase database); 27 | 28 | PteroAction deleteDatabase(ClientDatabase database); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ClientServerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 21 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 22 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 23 | import com.mattmalec.pterodactyl4j.requests.Route; 24 | import org.json.JSONObject; 25 | 26 | public class ClientServerManager { 27 | 28 | private final ClientServer server; 29 | private final PteroClientImpl impl; 30 | 31 | public ClientServerManager(ClientServer server, PteroClientImpl impl) { 32 | this.server = server; 33 | this.impl = impl; 34 | } 35 | 36 | public PteroAction setName(String name) { 37 | JSONObject obj = new JSONObject().put("name", name); 38 | return PteroActionImpl.onRequestExecute( 39 | impl.getP4J(), 40 | Route.Client.RENAME_SERVER.compile(server.getIdentifier()), 41 | PteroActionImpl.getRequestBody(obj)); 42 | } 43 | 44 | public PteroAction reinstall() { 45 | return PteroActionImpl.onRequestExecute( 46 | impl.getP4J(), Route.Client.REINSTALL_SERVER.compile(server.getIdentifier())); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/CompressAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.File; 21 | import com.mattmalec.pterodactyl4j.client.entities.GenericFile; 22 | 23 | public interface CompressAction extends PteroAction { 24 | 25 | CompressAction addFile(GenericFile file); 26 | 27 | CompressAction addFiles(GenericFile file, GenericFile... files); 28 | 29 | CompressAction clearFiles(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/CreateDirectoryAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Directory; 21 | 22 | public interface CreateDirectoryAction extends PteroAction { 23 | 24 | CreateDirectoryAction setName(String name); 25 | 26 | CreateDirectoryAction setRoot(Directory directory); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/DeleteAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.GenericFile; 21 | 22 | public interface DeleteAction extends PteroAction { 23 | 24 | DeleteAction addFile(GenericFile file); 25 | 26 | DeleteAction addFiles(GenericFile file, GenericFile... files); 27 | 28 | DeleteAction clearFiles(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/FileManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Directory; 21 | import com.mattmalec.pterodactyl4j.client.entities.DownloadableFile; 22 | import com.mattmalec.pterodactyl4j.client.entities.File; 23 | 24 | public interface FileManager { 25 | 26 | CreateDirectoryAction createDirectory(); 27 | 28 | PteroAction createFile(Directory directory, String name, String content); 29 | 30 | UploadFileAction upload(Directory directory); 31 | 32 | RenameAction rename(); 33 | 34 | CompressAction compress(); 35 | 36 | PteroAction decompress(File compressedFile); 37 | 38 | DeleteAction delete(); 39 | 40 | PteroAction retrieveContent(File file); 41 | 42 | PteroAction retrieveDownload(File file); 43 | 44 | PteroAction write(File file, String content); 45 | 46 | PteroAction copy(File file); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/RenameAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.GenericFile; 21 | 22 | public interface RenameAction extends PteroAction { 23 | 24 | RenameAction addFile(GenericFile file, String newName); 25 | 26 | RenameAction clearFiles(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ScheduleAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Cron; 21 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 22 | 23 | public interface ScheduleAction extends PteroAction { 24 | 25 | ScheduleAction setName(String name); 26 | 27 | ScheduleAction setActive(boolean active); 28 | 29 | ScheduleAction setWhenServerIsOnline(boolean whenServerIsOnline); 30 | 31 | ScheduleAction setCron(Cron cron); 32 | 33 | ScheduleAction setCronExpression(String expression); 34 | 35 | ScheduleAction setMinute(String minute); 36 | 37 | ScheduleAction setHour(String hour); 38 | 39 | ScheduleAction setDayOfWeek(String dayOfWeek); 40 | 41 | ScheduleAction setDayOfMonth(String dayOfMonth); 42 | 43 | ScheduleAction setMonth(String month); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ScheduleManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 21 | 22 | public interface ScheduleManager { 23 | 24 | ScheduleAction createSchedule(); 25 | 26 | ScheduleAction editSchedule(Schedule schedule); 27 | 28 | PteroAction delete(Schedule schedule); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ScheduleTaskAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PowerAction; 20 | import com.mattmalec.pterodactyl4j.PteroAction; 21 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 22 | 23 | public interface ScheduleTaskAction extends PteroAction { 24 | 25 | ScheduleTaskAction setAction(Schedule.ScheduleTask.ScheduleAction action); 26 | 27 | ScheduleTaskAction setPowerPayload(PowerAction payload); 28 | 29 | ScheduleTaskAction setPayload(String payload); 30 | 31 | ScheduleTaskAction setContinueOnFailure(boolean continueOnFailure); 32 | 33 | default ScheduleTaskAction setTimeOffset(int seconds) { 34 | return setTimeOffset(Integer.toUnsignedString(seconds)); 35 | } 36 | 37 | ScheduleTaskAction setTimeOffset(String seconds); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/ScheduleTaskManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.Schedule; 21 | 22 | public interface ScheduleTaskManager { 23 | 24 | ScheduleTaskAction createTask(); 25 | 26 | ScheduleTaskAction editTask(Schedule.ScheduleTask task); 27 | 28 | PteroAction deleteTask(Schedule.ScheduleTask task); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/SubuserAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.Permission; 20 | import com.mattmalec.pterodactyl4j.PteroAction; 21 | import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser; 22 | 23 | public interface SubuserAction extends PteroAction { 24 | 25 | SubuserAction setPermissions(Permission... permissions); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/SubuserCreationAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | public interface SubuserCreationAction extends SubuserAction { 20 | 21 | SubuserCreationAction setEmail(String email); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/SubuserManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser; 21 | 22 | public interface SubuserManager { 23 | 24 | SubuserCreationAction createUser(); 25 | 26 | SubuserAction editUser(ClientSubuser subuser); 27 | 28 | PteroAction deleteUser(ClientSubuser subuser); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/managers/UploadFileAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.managers; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.utils.Checks; 21 | import java.io.ByteArrayInputStream; 22 | import java.io.File; 23 | import java.io.InputStream; 24 | 25 | public interface UploadFileAction extends PteroAction { 26 | 27 | UploadFileAction addFile(InputStream data, String name); 28 | 29 | default UploadFileAction addFile(byte[] data, String name) { 30 | Checks.notNull(data, "Data"); 31 | return addFile(new ByteArrayInputStream(data), name); 32 | } 33 | 34 | default UploadFileAction addFile(final File file) { 35 | Checks.notNull(file, "File"); 36 | return addFile(file, file.getName()); 37 | } 38 | 39 | UploadFileAction addFile(File file, String name); 40 | 41 | UploadFileAction clearFiles(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/WebSocketAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws; 18 | 19 | import org.json.JSONArray; 20 | import org.json.JSONObject; 21 | 22 | public final class WebSocketAction { 23 | 24 | public static final String AUTH = "auth"; 25 | public static final String SET_STATE = "set state"; 26 | public static final String SEND_LOGS = "send logs"; 27 | public static final String SEND_COMMAND = "send command"; 28 | public static final String SEND_STATS = "send stats"; 29 | 30 | public static String create(String event, String argument) { 31 | JSONObject returnable = new JSONObject(); 32 | JSONArray args = new JSONArray(); 33 | args.put(argument); 34 | returnable.put("event", event).put("args", args); 35 | return returnable.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/AuthSuccessEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class AuthSuccessEvent extends Event { 24 | 25 | public AuthSuccessEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager) { 26 | super(api, server, manager); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/BackupCompletedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events; 18 | 19 | import com.mattmalec.pterodactyl4j.DataType; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 21 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 22 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 23 | import org.json.JSONObject; 24 | 25 | public class BackupCompletedEvent extends Event { 26 | 27 | private final JSONObject json; 28 | 29 | public BackupCompletedEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, JSONObject json) { 30 | super(api, server, manager); 31 | this.json = json; 32 | } 33 | 34 | public boolean isSuccessful() { 35 | return json.getBoolean("is_successful"); 36 | } 37 | 38 | public String getChecksum() { 39 | return json.getString("checksum"); 40 | } 41 | 42 | public String getChecksumType() { 43 | return json.getString("checksum_type"); 44 | } 45 | 46 | public long getSize() { 47 | return json.getLong("file_size"); 48 | } 49 | 50 | public String getSizeFormatted(DataType dataType) { 51 | return String.format("%.2f %s", getSize() / (dataType.getMbValue() * Math.pow(2, 20)), dataType.name()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/StatusUpdateEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events; 18 | 19 | import com.mattmalec.pterodactyl4j.UtilizationState; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 21 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 22 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 23 | 24 | public class StatusUpdateEvent extends Event { 25 | 26 | private final UtilizationState state; 27 | 28 | public StatusUpdateEvent( 29 | PteroClientImpl api, ClientServer server, WebSocketManager manager, UtilizationState state) { 30 | super(api, server, manager); 31 | this.state = state; 32 | } 33 | 34 | public UtilizationState getState() { 35 | return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/connection/ConnectedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.connection; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class ConnectedEvent extends ConnectionEvent { 24 | 25 | public ConnectedEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean connected) { 26 | super(api, server, manager, connected); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/connection/ConnectionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.connection; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public abstract class ConnectionEvent extends Event { 25 | 26 | private final boolean connected; 27 | 28 | public ConnectionEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean connected) { 29 | super(api, server, manager); 30 | this.connected = connected; 31 | } 32 | 33 | public boolean isConnected() { 34 | return connected; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/connection/DisconnectedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.connection; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class DisconnectedEvent extends DisconnectionEvent { 24 | 25 | public DisconnectedEvent( 26 | PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean connected, int closeCode) { 27 | super(api, server, manager, connected, closeCode); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/connection/DisconnectingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.connection; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class DisconnectingEvent extends DisconnectionEvent { 24 | 25 | public DisconnectingEvent( 26 | PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean connected, int closeCode) { 27 | super(api, server, manager, connected, closeCode); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/connection/DisconnectionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.connection; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public abstract class DisconnectionEvent extends ConnectionEvent { 24 | 25 | protected final int closeCode; 26 | 27 | public DisconnectionEvent( 28 | PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean connected, int closeCode) { 29 | super(api, server, manager, connected); 30 | this.closeCode = closeCode; 31 | } 32 | 33 | public int getCloseCode() { 34 | return closeCode; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/error/DaemonErrorEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.error; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public class DaemonErrorEvent extends Event { 25 | 26 | private final String message; 27 | 28 | public DaemonErrorEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String message) { 29 | super(api, server, manager); 30 | this.message = message; 31 | } 32 | 33 | public String getMessage() { 34 | return message; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/error/JWTErrorEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.error; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public class JWTErrorEvent extends Event { 25 | 26 | private final String message; 27 | 28 | public JWTErrorEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String message) { 29 | super(api, server, manager); 30 | this.message = message; 31 | } 32 | 33 | public String getMessage() { 34 | return message; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/install/InstallCompletedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.install; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class InstallCompletedEvent extends InstallEvent { 24 | 25 | public InstallCompletedEvent( 26 | PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean installed) { 27 | super(api, server, manager, installed); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/install/InstallEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.install; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public abstract class InstallEvent extends Event { 25 | 26 | private final boolean installed; 27 | 28 | public InstallEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean installed) { 29 | super(api, server, manager); 30 | this.installed = installed; 31 | } 32 | 33 | public boolean isInstalled() { 34 | return installed; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/install/InstallStartedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.install; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | // this event is only called if skip egg scripts is disabled 24 | public class InstallStartedEvent extends InstallEvent { 25 | 26 | public InstallStartedEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean installed) { 27 | super(api, server, manager, installed); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/output/ConsoleOutputEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.output; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class ConsoleOutputEvent extends OutputEvent { 24 | 25 | public ConsoleOutputEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String line) { 26 | super(api, server, manager, line); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/output/DaemonMessageEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.output; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class DaemonMessageEvent extends OutputEvent { 24 | 25 | public DaemonMessageEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String line) { 26 | super(api, server, manager, line); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/output/InstallOutputEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.output; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class InstallOutputEvent extends OutputEvent { 24 | 25 | public InstallOutputEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String line) { 26 | super(api, server, manager, line); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/output/OutputEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.output; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public abstract class OutputEvent extends Event { 25 | 26 | private final String line; 27 | 28 | public OutputEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String line) { 29 | super(api, server, manager); 30 | this.line = line; 31 | } 32 | 33 | public String getLine() { 34 | return line; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/token/TokenEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.token; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public abstract class TokenEvent extends Event { 25 | 26 | private final boolean expired; 27 | 28 | public TokenEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean expired) { 29 | super(api, server, manager); 30 | this.expired = expired; 31 | } 32 | 33 | public boolean isExpired() { 34 | return expired; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/token/TokenExpiredEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.token; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class TokenExpiredEvent extends TokenEvent { 24 | 25 | public TokenExpiredEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean expired) { 26 | super(api, server, manager, expired); 27 | } 28 | 29 | @Override 30 | public boolean isExpired() { 31 | return super.isExpired(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/token/TokenExpiringEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.token; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public class TokenExpiringEvent extends TokenEvent { 24 | 25 | public TokenExpiringEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, boolean expired) { 26 | super(api, server, manager, expired); 27 | } 28 | 29 | @Override 30 | public boolean isExpired() { 31 | return super.isExpired(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/transfer/TransferLogEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.transfer; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public class TransferLogEvent extends Event { 25 | 26 | private final String line; 27 | 28 | public TransferLogEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String line) { 29 | super(api, server, manager); 30 | this.line = line; 31 | } 32 | 33 | public String getLine() { 34 | return line; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/events/transfer/TransferStatusEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.events.transfer; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 23 | 24 | public class TransferStatusEvent extends Event { 25 | 26 | private final String status; 27 | 28 | public TransferStatusEvent(PteroClientImpl api, ClientServer server, WebSocketManager manager, String status) { 29 | super(api, server, manager); 30 | this.status = status; 31 | } 32 | 33 | public TransferStatus getStatus() { 34 | return TransferStatus.valueOf(status.toUpperCase()); 35 | } 36 | 37 | public enum TransferStatus { 38 | STARTING, 39 | ARCHIVED, 40 | SUCCESS, 41 | FAILURE 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/AuthSuccessHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.WebSocketClient; 23 | import com.mattmalec.pterodactyl4j.client.ws.events.AuthSuccessEvent; 24 | 25 | public class AuthSuccessHandler extends ClientSocketHandler { 26 | 27 | public AuthSuccessHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 28 | super(client, server, manager); 29 | } 30 | 31 | @Override 32 | public void handleInternally(String content) { 33 | getManager().getEventManager().handle(new AuthSuccessEvent(getClient(), getServer(), getManager())); 34 | WebSocketClient.WEBSOCKET_LOG.info( 35 | String.format("Authorized websocket for server %s", getServer().getIdentifier())); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/BackupCompletedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.BackupCompletedEvent; 23 | import org.json.JSONObject; 24 | 25 | public class BackupCompletedHandler extends ClientSocketHandler { 26 | 27 | public BackupCompletedHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 28 | super(client, server, manager); 29 | } 30 | 31 | @Override 32 | public void handleInternally(String content) { 33 | getManager() 34 | .getEventManager() 35 | .handle(new BackupCompletedEvent(getClient(), getServer(), getManager(), new JSONObject(content))); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/ClientSocketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | 23 | public abstract class ClientSocketHandler { 24 | 25 | private final PteroClientImpl client; 26 | private ClientServer server; 27 | private final WebSocketManager manager; 28 | 29 | public ClientSocketHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 30 | this.client = client; 31 | this.server = server; 32 | this.manager = manager; 33 | } 34 | 35 | protected PteroClientImpl getClient() { 36 | return client; 37 | } 38 | 39 | public ClientSocketHandler setServer(ClientServer server) { 40 | this.server = server; 41 | return this; 42 | } 43 | 44 | protected ClientServer getServer() { 45 | return server; 46 | } 47 | 48 | protected WebSocketManager getManager() { 49 | return manager; 50 | } 51 | 52 | public abstract void handleInternally(String content); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/ConsoleOuputHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.output.ConsoleOutputEvent; 23 | 24 | public class ConsoleOuputHandler extends ClientSocketHandler { 25 | 26 | public ConsoleOuputHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new ConsoleOutputEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/DaemonErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.error.DaemonErrorEvent; 23 | 24 | public class DaemonErrorHandler extends ClientSocketHandler { 25 | 26 | public DaemonErrorHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new DaemonErrorEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/DaemonMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.output.DaemonMessageEvent; 23 | 24 | public class DaemonMessageHandler extends ClientSocketHandler { 25 | 26 | public DaemonMessageHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new DaemonMessageEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/InstallCompletedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.install.InstallCompletedEvent; 23 | 24 | public class InstallCompletedHandler extends ClientSocketHandler { 25 | 26 | public InstallCompletedHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new InstallCompletedEvent(getClient(), getServer(), getManager(), true)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/InstallOuputHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.output.InstallOutputEvent; 23 | 24 | public class InstallOuputHandler extends ClientSocketHandler { 25 | 26 | public InstallOuputHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new InstallOutputEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/InstallStartedHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.install.InstallStartedEvent; 23 | 24 | public class InstallStartedHandler extends ClientSocketHandler { 25 | 26 | public InstallStartedHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new InstallStartedEvent(getClient(), getServer(), getManager(), false)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/JWTErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.WebSocketClient; 23 | import com.mattmalec.pterodactyl4j.client.ws.events.error.JWTErrorEvent; 24 | 25 | public class JWTErrorHandler extends ClientSocketHandler { 26 | 27 | private final WebSocketClient webSocket; 28 | 29 | public JWTErrorHandler( 30 | PteroClientImpl client, ClientServer server, WebSocketManager manager, WebSocketClient webSocket) { 31 | super(client, server, manager); 32 | this.webSocket = webSocket; 33 | } 34 | 35 | @Override 36 | public void handleInternally(String content) { 37 | if (content.equals("jwt: exp claim is invalid")) webSocket.sendAuthenticate(); 38 | getManager().getEventManager().handle(new JWTErrorEvent(getClient(), getServer(), getManager(), content)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/StatsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.StatsUpdateEvent; 23 | import org.json.JSONObject; 24 | 25 | public class StatsHandler extends ClientSocketHandler { 26 | 27 | public StatsHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 28 | super(client, server, manager); 29 | } 30 | 31 | @Override 32 | public void handleInternally(String content) { 33 | JSONObject json = new JSONObject(content); 34 | getManager().getEventManager().handle(new StatsUpdateEvent(getClient(), getServer(), getManager(), json)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/StatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.UtilizationState; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 21 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 22 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 23 | import com.mattmalec.pterodactyl4j.client.ws.events.StatusUpdateEvent; 24 | 25 | public class StatusHandler extends ClientSocketHandler { 26 | 27 | public StatusHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 28 | super(client, server, manager); 29 | } 30 | 31 | @Override 32 | public void handleInternally(String content) { 33 | getManager() 34 | .getEventManager() 35 | .handle(new StatusUpdateEvent(getClient(), getServer(), getManager(), UtilizationState.of(content))); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/TokenExpiredHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.WebSocketClient; 23 | 24 | public class TokenExpiredHandler extends ClientSocketHandler { 25 | 26 | private final WebSocketClient webSocketClient; 27 | 28 | public TokenExpiredHandler( 29 | PteroClientImpl client, ClientServer server, WebSocketManager manager, WebSocketClient webSocketClient) { 30 | super(client, server, manager); 31 | this.webSocketClient = webSocketClient; 32 | } 33 | 34 | @Override 35 | public void handleInternally(String content) { 36 | webSocketClient.sendAuthenticate(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/TokenExpiringHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.WebSocketClient; 23 | 24 | public class TokenExpiringHandler extends ClientSocketHandler { 25 | 26 | private final WebSocketClient webSocketClient; 27 | 28 | public TokenExpiringHandler( 29 | PteroClientImpl client, ClientServer server, WebSocketManager manager, WebSocketClient webSocketClient) { 30 | super(client, server, manager); 31 | this.webSocketClient = webSocketClient; 32 | } 33 | 34 | @Override 35 | public void handleInternally(String content) { 36 | webSocketClient.sendAuthenticate(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/TransferLogHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.transfer.TransferLogEvent; 23 | 24 | public class TransferLogHandler extends ClientSocketHandler { 25 | 26 | public TransferLogHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new TransferLogEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/handle/TransferStatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.handle; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.ClientServer; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 21 | import com.mattmalec.pterodactyl4j.client.managers.WebSocketManager; 22 | import com.mattmalec.pterodactyl4j.client.ws.events.transfer.TransferStatusEvent; 23 | 24 | public class TransferStatusHandler extends ClientSocketHandler { 25 | 26 | public TransferStatusHandler(PteroClientImpl client, ClientServer server, WebSocketManager manager) { 27 | super(client, server, manager); 28 | } 29 | 30 | @Override 31 | public void handleInternally(String content) { 32 | getManager().getEventManager().handle(new TransferStatusEvent(getClient(), getServer(), getManager(), content)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/hooks/ClientSocketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.hooks; 18 | 19 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 20 | 21 | @FunctionalInterface 22 | public interface ClientSocketListener { 23 | 24 | void onEvent(Event event); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/client/ws/hooks/IClientListenerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.client.ws.hooks; 18 | 19 | import com.mattmalec.pterodactyl4j.client.ws.events.Event; 20 | import java.util.List; 21 | 22 | public interface IClientListenerManager { 23 | 24 | void register(Object listener); 25 | 26 | void unregister(Object listener); 27 | 28 | List getRegisteredListeners(); 29 | 30 | void handle(Event event); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/FeatureLimit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities; 18 | 19 | public interface FeatureLimit { 20 | 21 | long getDatabasesLong(); 22 | 23 | default String getDatabases() { 24 | return Long.toUnsignedString(getDatabasesLong()); 25 | } 26 | 27 | long getAllocationsLong(); 28 | 29 | default String getAllocations() { 30 | return Long.toUnsignedString(getAllocationsLong()); 31 | } 32 | 33 | long getBackupsLong(); 34 | 35 | default String getBackups() { 36 | return Long.toUnsignedString(getBackupsLong()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/IPermissionHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.Permission; 20 | import java.util.EnumSet; 21 | 22 | public interface IPermissionHolder { 23 | 24 | EnumSet getPermissions(); 25 | 26 | boolean hasPermission(Permission... permission); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/Limit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities; 18 | 19 | public interface Limit { 20 | 21 | long getMemoryLong(); 22 | 23 | default String getMemory() { 24 | return Long.toUnsignedString(getMemoryLong()); 25 | } 26 | 27 | long getSwapLong(); 28 | 29 | default String getSwap() { 30 | return Long.toUnsignedString(getSwapLong()); 31 | } 32 | 33 | long getDiskLong(); 34 | 35 | default String getDisk() { 36 | return Long.toUnsignedString(getDiskLong()); 37 | } 38 | 39 | long getIOLong(); 40 | 41 | default String getIO() { 42 | return Long.toUnsignedString(getIOLong()); 43 | } 44 | 45 | long getCPULong(); 46 | 47 | default String getCPU() { 48 | return Long.toUnsignedString(getCPULong()); 49 | } 50 | 51 | String getThreads(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/P4J.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.PteroApplication; 20 | import com.mattmalec.pterodactyl4j.client.entities.PteroClient; 21 | import com.mattmalec.pterodactyl4j.requests.Requester; 22 | import java.util.concurrent.ExecutorService; 23 | import java.util.concurrent.ScheduledExecutorService; 24 | import okhttp3.OkHttpClient; 25 | 26 | public interface P4J { 27 | 28 | String getToken(); 29 | 30 | Requester getRequester(); 31 | 32 | String getApplicationUrl(); 33 | 34 | OkHttpClient getHttpClient(); 35 | 36 | ExecutorService getCallbackPool(); 37 | 38 | ExecutorService getActionPool(); 39 | 40 | ScheduledExecutorService getRateLimitPool(); 41 | 42 | ExecutorService getSupplierPool(); 43 | 44 | OkHttpClient getWebSocketClient(); 45 | 46 | String getUserAgent(); 47 | 48 | PteroClient asClient(); 49 | 50 | PteroApplication asApplication(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities; 18 | 19 | /** 20 | * Represents a Pterodactyl {@link com.mattmalec.pterodactyl4j.entities.User User}. 21 | * This should contain all information provided from the Pterodactyl instance about a User. 22 | */ 23 | public interface User { 24 | 25 | /** 26 | * The username of the User 27 | * 28 | * @return Never-null String containing the User's username. 29 | */ 30 | String getUserName(); 31 | 32 | /** 33 | * The email of the User 34 | * 35 | * @return Never-null String containing the User's email. 36 | */ 37 | String getEmail(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/impl/DatabasePasswordImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities.impl; 18 | 19 | import org.json.JSONObject; 20 | 21 | public class DatabasePasswordImpl { 22 | 23 | private final JSONObject json; 24 | 25 | public DatabasePasswordImpl(JSONObject json) { 26 | this.json = json.getJSONObject("attributes"); 27 | } 28 | 29 | public String getPassword() { 30 | return json.getString("password"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/impl/FeatureLimitImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.entities.FeatureLimit; 20 | import org.json.JSONObject; 21 | 22 | public class FeatureLimitImpl implements FeatureLimit { 23 | 24 | private final JSONObject json; 25 | 26 | public FeatureLimitImpl(JSONObject json) { 27 | this.json = json; 28 | } 29 | 30 | @Override 31 | public long getDatabasesLong() { 32 | return json.getLong("databases"); 33 | } 34 | 35 | @Override 36 | public long getAllocationsLong() { 37 | return json.getLong("allocations"); 38 | } 39 | 40 | @Override 41 | public long getBackupsLong() { 42 | return json.getLong("backups"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/entities/impl/LimitImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.entities.impl; 18 | 19 | import com.mattmalec.pterodactyl4j.entities.Limit; 20 | import org.json.JSONObject; 21 | 22 | public class LimitImpl implements Limit { 23 | 24 | private final JSONObject json; 25 | 26 | public LimitImpl(JSONObject json) { 27 | this.json = json; 28 | } 29 | 30 | @Override 31 | public long getMemoryLong() { 32 | return json.getLong("memory"); 33 | } 34 | 35 | @Override 36 | public long getSwapLong() { 37 | return json.getLong("swap"); 38 | } 39 | 40 | @Override 41 | public long getDiskLong() { 42 | return json.getLong("disk"); 43 | } 44 | 45 | @Override 46 | public long getIOLong() { 47 | return json.getLong("io"); 48 | } 49 | 50 | @Override 51 | public long getCPULong() { 52 | return json.getLong("cpu"); 53 | } 54 | 55 | @Override 56 | public String getThreads() { 57 | return json.optString("threads"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/FileUploadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | import org.json.JSONObject; 20 | 21 | public class FileUploadException extends HttpException { 22 | 23 | public FileUploadException(int code, JSONObject json) { 24 | super(code + ": " + json.getString("error")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/HttpException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | import com.mattmalec.pterodactyl4j.requests.Response; 20 | import org.json.JSONObject; 21 | 22 | public class HttpException extends PteroException { 23 | 24 | public HttpException(String message) { 25 | super(message); 26 | } 27 | 28 | private static String create(String text, Response response) { 29 | if (response.isEmpty()) return text; 30 | else return formatMessage(text, response.getObject()); 31 | } 32 | 33 | private static String formatMessage(String text, JSONObject json) { 34 | StringBuilder message = new StringBuilder(text + "\n\n"); 35 | for (Object o : json.getJSONArray("errors")) { 36 | JSONObject obj = new JSONObject(o.toString()); 37 | message.append("\t- ").append(obj.getString("detail")).append("\n"); 38 | } 39 | return message.toString(); 40 | } 41 | 42 | public HttpException(String text, Response response) { 43 | super(create(text, response)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/IllegalActionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | public class IllegalActionException extends PteroException { 20 | 21 | public IllegalActionException(String message) { 22 | super(message); 23 | } 24 | 25 | // Save this for later 26 | // 27 | // public IllegalActionException(String text, JSONObject json) { 28 | // String message = text + "\n\n"; 29 | // for(Object o : json.getJSONArray("errors")) { 30 | // JSONObject obj = new JSONObject(o.toString()); 31 | // message += "\t- " + obj.getString("detail") + "\n"; 32 | // } 33 | // throw new IllegalActionException(message); 34 | // } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/LoginException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | public class LoginException extends PteroException { 20 | 21 | public LoginException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/MissingActionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | import org.json.JSONObject; 20 | 21 | public class MissingActionException extends PteroException { 22 | 23 | public MissingActionException(String text, JSONObject json) { 24 | super(formatMessage(text, json)); 25 | } 26 | 27 | public static String formatMessage(String text, JSONObject json) { 28 | StringBuilder message = new StringBuilder(text + "\n\n"); 29 | for (Object o : json.getJSONArray("errors")) { 30 | JSONObject obj = new JSONObject(o.toString()); 31 | message.append("\t- ") 32 | .append(obj.getString("detail")) 33 | .append(" (Source: ") 34 | .append(obj.getJSONObject("meta").getString("source_field")) 35 | .append(")\n"); 36 | } 37 | return message.toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/NotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | public class NotFoundException extends PteroException { 20 | 21 | public NotFoundException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/PteroException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | public class PteroException extends RuntimeException { 20 | 21 | public PteroException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/RateLimitedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | import com.mattmalec.pterodactyl4j.requests.Route; 20 | 21 | public class RateLimitedException extends HttpException { 22 | 23 | public RateLimitedException(Route.CompiledRoute route, long retryAfter) { 24 | super(String.format( 25 | "The request was rate limited. Retry-After: %d Route: %s", retryAfter, route.getCompiledRoute())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/exceptions/ServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.exceptions; 18 | 19 | public class ServerException extends PteroException { 20 | 21 | public ServerException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/DeferredPteroAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.entities.P4J; 21 | import com.mattmalec.pterodactyl4j.exceptions.RateLimitedException; 22 | import java.util.concurrent.CompletableFuture; 23 | import java.util.function.Consumer; 24 | import java.util.function.Supplier; 25 | 26 | public class DeferredPteroAction implements PteroAction { 27 | 28 | private final P4J api; 29 | private final Supplier value; 30 | 31 | public DeferredPteroAction(P4J api, Supplier value) { 32 | this.api = api; 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public P4J getP4J() { 38 | return api; 39 | } 40 | 41 | @Override 42 | public T execute(boolean shouldQueue) throws RateLimitedException { 43 | return value.get(); 44 | } 45 | 46 | @Override 47 | public void executeAsync(Consumer success, Consumer failure) { 48 | CompletableFuture.supplyAsync(value, api.getSupplierPool()) 49 | .thenAcceptAsync(success == null ? PteroAction.getDefaultSuccess() : success); 50 | } 51 | 52 | @Override 53 | public PteroAction deadline(long timestamp) { 54 | return this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/Method.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests; 18 | 19 | public enum Method { 20 | GET, 21 | POST, 22 | PUT, 23 | PATCH, 24 | DELETE 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/RequestFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import okhttp3.RequestBody; 21 | 22 | public class RequestFuture extends CompletableFuture { 23 | 24 | private final Request request; 25 | 26 | public RequestFuture( 27 | PteroActionImpl action, 28 | Route.CompiledRoute route, 29 | RequestBody requestBody, 30 | boolean shouldQueue, 31 | long deadline) { 32 | this.request = new Request<>( 33 | action, this::complete, this::completeExceptionally, route, requestBody, shouldQueue, deadline); 34 | action.getP4J().getRequester().request(this.request); 35 | } 36 | 37 | @Override 38 | public boolean cancel(final boolean mayInterrupt) { 39 | if (this.request != null) this.request.cancel(); 40 | 41 | return (!isDone() && !isCancelled()) && super.cancel(mayInterrupt); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractAllocationAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.impl.PteroApplicationImpl; 20 | import com.mattmalec.pterodactyl4j.application.managers.AllocationAction; 21 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 22 | import com.mattmalec.pterodactyl4j.requests.Route; 23 | import java.util.Arrays; 24 | import java.util.HashSet; 25 | import java.util.Set; 26 | 27 | public abstract class AbstractAllocationAction extends PteroActionImpl implements AllocationAction { 28 | 29 | protected String ip; 30 | protected String alias; 31 | protected Set portSet; 32 | 33 | public AbstractAllocationAction(PteroApplicationImpl impl, Route.CompiledRoute route) { 34 | super(impl.getP4J(), route); 35 | this.portSet = new HashSet<>(); 36 | } 37 | 38 | @Override 39 | public AllocationAction setIP(String ip) { 40 | this.ip = ip; 41 | return this; 42 | } 43 | 44 | @Override 45 | public AllocationAction setAlias(String alias) { 46 | this.alias = alias; 47 | return this; 48 | } 49 | 50 | @Override 51 | public AllocationAction setPorts(String... ports) { 52 | this.portSet = new HashSet<>(Arrays.asList(ports)); 53 | return this; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractDatabaseAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action; 18 | 19 | import com.mattmalec.pterodactyl4j.entities.P4J; 20 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 21 | import com.mattmalec.pterodactyl4j.requests.Request; 22 | import com.mattmalec.pterodactyl4j.requests.Response; 23 | import com.mattmalec.pterodactyl4j.requests.Route; 24 | import java.util.function.BiFunction; 25 | 26 | public abstract class AbstractDatabaseAction extends PteroActionImpl { 27 | 28 | protected String name; 29 | protected String remote; 30 | 31 | public AbstractDatabaseAction(P4J api, Route.CompiledRoute route, BiFunction, T> handler) { 32 | super(api, route, handler); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractLocationAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.Location; 20 | import com.mattmalec.pterodactyl4j.application.entities.impl.LocationImpl; 21 | import com.mattmalec.pterodactyl4j.application.entities.impl.PteroApplicationImpl; 22 | import com.mattmalec.pterodactyl4j.application.managers.LocationAction; 23 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 24 | import com.mattmalec.pterodactyl4j.requests.Route; 25 | 26 | public abstract class AbstractLocationAction extends PteroActionImpl implements LocationAction { 27 | 28 | protected String shortCode; 29 | protected String description; 30 | 31 | public AbstractLocationAction(PteroApplicationImpl impl, Route.CompiledRoute route) { 32 | super(impl.getP4J(), route, (response, request) -> new LocationImpl(response.getObject(), impl)); 33 | } 34 | 35 | @Override 36 | public LocationAction setShortCode(String shortCode) { 37 | this.shortCode = shortCode; 38 | return this; 39 | } 40 | 41 | @Override 42 | public LocationAction setDescription(String description) { 43 | this.description = description; 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractManagerBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action; 18 | 19 | import com.mattmalec.pterodactyl4j.application.entities.ApplicationServer; 20 | import com.mattmalec.pterodactyl4j.application.entities.impl.ApplicationServerImpl; 21 | import com.mattmalec.pterodactyl4j.application.entities.impl.PteroApplicationImpl; 22 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 23 | import com.mattmalec.pterodactyl4j.requests.Route; 24 | 25 | public abstract class AbstractManagerBase extends PteroActionImpl { 26 | 27 | protected long set = 0; 28 | 29 | public AbstractManagerBase(PteroApplicationImpl impl, Route.CompiledRoute route) { 30 | super(impl.getP4J(), route, (response, request) -> new ApplicationServerImpl(impl, response.getObject())); 31 | } 32 | 33 | protected boolean shouldUpdate(long bit) { 34 | return (set & bit) == bit; 35 | } 36 | 37 | protected void reset() { 38 | this.set = 0; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractSubuserAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action; 18 | 19 | import com.mattmalec.pterodactyl4j.Permission; 20 | import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser; 21 | import com.mattmalec.pterodactyl4j.client.entities.impl.ClientSubuserImpl; 22 | import com.mattmalec.pterodactyl4j.client.entities.impl.PteroClientImpl; 23 | import com.mattmalec.pterodactyl4j.client.managers.SubuserAction; 24 | import com.mattmalec.pterodactyl4j.requests.PteroActionImpl; 25 | import com.mattmalec.pterodactyl4j.requests.Route; 26 | import java.util.Arrays; 27 | import java.util.EnumSet; 28 | 29 | public abstract class AbstractSubuserAction extends PteroActionImpl implements SubuserAction { 30 | 31 | protected EnumSet permissions; 32 | 33 | public AbstractSubuserAction(PteroClientImpl impl, Route.CompiledRoute route) { 34 | super(impl.getP4J(), route, (response, request) -> new ClientSubuserImpl(response.getObject())); 35 | this.permissions = EnumSet.noneOf(Permission.class); 36 | } 37 | 38 | @Override 39 | public SubuserAction setPermissions(Permission... permissions) { 40 | this.permissions.addAll(Arrays.asList(permissions)); 41 | return this; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/operator/MapPteroAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action.operator; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import java.util.function.Consumer; 21 | import java.util.function.Function; 22 | 23 | // big thanks to JDA for this tremendous code 24 | 25 | public class MapPteroAction extends PteroActionOperator { 26 | 27 | private final Function function; 28 | 29 | public MapPteroAction(PteroAction action, Function function) { 30 | super(action); 31 | this.function = function; 32 | } 33 | 34 | @Override 35 | public void executeAsync(Consumer success, Consumer failure) { 36 | action.executeAsync( 37 | (result) -> doSuccess(success, function.apply(result)), (error) -> doFailure(failure, error)); 38 | } 39 | 40 | @Override 41 | public O execute(boolean shouldQueue) { 42 | return function.apply(action.execute(shouldQueue)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/requests/action/operator/PteroActionOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.requests.action.operator; 18 | 19 | import com.mattmalec.pterodactyl4j.PteroAction; 20 | import com.mattmalec.pterodactyl4j.entities.P4J; 21 | import java.util.function.Consumer; 22 | 23 | // big thanks to JDA for this tremendous code 24 | 25 | public abstract class PteroActionOperator implements PteroAction { 26 | 27 | protected final PteroAction action; 28 | protected long deadline = 0; 29 | 30 | public PteroActionOperator(PteroAction action) { 31 | this.action = action; 32 | } 33 | 34 | protected static void doSuccess(Consumer callback, E value) { 35 | if (callback == null) PteroAction.getDefaultSuccess().accept(value); 36 | else callback.accept(value); 37 | } 38 | 39 | protected static void doFailure(Consumer callback, Throwable throwable) { 40 | if (callback == null) PteroAction.getDefaultFailure().accept(throwable); 41 | else callback.accept(throwable); 42 | } 43 | 44 | @Override 45 | public PteroAction deadline(long timestamp) { 46 | this.deadline = timestamp; 47 | action.deadline(timestamp); 48 | return this; 49 | } 50 | 51 | @Override 52 | public P4J getP4J() { 53 | return action.getP4J(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/BufferedRequestBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import java.io.IOException; 20 | import okhttp3.MediaType; 21 | import okhttp3.RequestBody; 22 | import okio.BufferedSink; 23 | import okio.BufferedSource; 24 | import okio.Okio; 25 | import okio.Source; 26 | 27 | // thank you jda 28 | public final class BufferedRequestBody extends RequestBody { 29 | private final Source source; 30 | private final MediaType type; 31 | private byte[] data; 32 | 33 | public BufferedRequestBody(Source source, MediaType type) { 34 | this.source = source; 35 | this.type = type; 36 | } 37 | 38 | @Override 39 | public MediaType contentType() { 40 | return type; 41 | } 42 | 43 | @Override 44 | public void writeTo(BufferedSink sink) throws IOException { 45 | if (data != null) { 46 | sink.write(data); 47 | return; 48 | } 49 | 50 | try (BufferedSource s = Okio.buffer(source)) { 51 | data = s.readByteArray(); 52 | sink.write(data); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/CronUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import com.mattmalec.pterodactyl4j.client.entities.Cron; 20 | import com.mattmalec.pterodactyl4j.client.entities.impl.CronImpl; 21 | 22 | public final class CronUtils { 23 | 24 | public static Cron ofExpression(String expression) { 25 | return CronImpl.ofExpression(expression); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | public final class ExceptionUtils { 20 | 21 | public static T appendCause(T throwable, Throwable cause) { 22 | Throwable t = throwable; 23 | while (t.getCause() != null) t = t.getCause(); 24 | t.initCause(cause); 25 | return throwable; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/LockUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import java.util.concurrent.TimeUnit; 20 | import java.util.concurrent.locks.Lock; 21 | import java.util.concurrent.locks.ReentrantLock; 22 | 23 | // i love you jda 24 | public final class LockUtils { 25 | 26 | public static void locked(ReentrantLock lock, Runnable task) { 27 | try { 28 | tryLock(lock); 29 | task.run(); 30 | } finally { 31 | if (lock.isHeldByCurrentThread()) lock.unlock(); 32 | } 33 | } 34 | 35 | public static void tryLock(Lock lock) { 36 | try { 37 | if (!lock.tryLock() && !lock.tryLock(10, TimeUnit.SECONDS)) 38 | throw new IllegalStateException("Could not acquire lock in a reasonable timeframe! (10 seconds)"); 39 | } catch (InterruptedException e) { 40 | throw new IllegalStateException("Unable to acquire lock while thread is interrupted!"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/NamedThreadFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import java.util.concurrent.ThreadFactory; 20 | 21 | public final class NamedThreadFactory implements ThreadFactory { 22 | 23 | private final String name; 24 | 25 | public NamedThreadFactory(String name) { 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | public Thread newThread(Runnable r) { 31 | Thread thread = new Thread(r, String.format("P4J-%s-Worker", name)); 32 | thread.setDaemon(true); 33 | return thread; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/PaginatedEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import org.json.JSONObject; 20 | 21 | public class PaginatedEntity { 22 | 23 | private final int total; 24 | private final int entitiesPerPage; 25 | private final int currentPage; 26 | private final int totalPages; 27 | 28 | private PaginatedEntity(int total, int entitiesPerPage, int currentPage, int totalPages) { 29 | this.total = total; 30 | this.entitiesPerPage = entitiesPerPage; 31 | this.currentPage = currentPage; 32 | this.totalPages = totalPages; 33 | } 34 | 35 | public static PaginatedEntity create(JSONObject json) { 36 | JSONObject object = json.getJSONObject("meta").getJSONObject("pagination"); 37 | return new PaginatedEntity( 38 | object.getInt("total"), 39 | object.getInt("per_page"), 40 | object.getInt("current_page"), 41 | object.getInt("total_pages")); 42 | } 43 | 44 | public int getTotal() { 45 | return total; 46 | } 47 | 48 | public int getEntitiesPerPage() { 49 | return entitiesPerPage; 50 | } 51 | 52 | public int getCurrentPage() { 53 | return currentPage; 54 | } 55 | 56 | public int getTotalPages() { 57 | return totalPages; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/Procedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | @FunctionalInterface 20 | public interface Procedure { 21 | 22 | boolean execute(T value); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/StreamUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | import java.util.stream.Collector; 22 | import java.util.stream.Collectors; 23 | 24 | public final class StreamUtils { 25 | 26 | public static Collector> toUnmodifiableList() { 27 | return Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList); 28 | } 29 | 30 | public static boolean compareString(String a, String b, boolean caseSensitive) { 31 | return caseSensitive ? a.equals(b) : a.equalsIgnoreCase(b); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/config/EndpointConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils.config; 18 | 19 | import com.mattmalec.pterodactyl4j.utils.Checks; 20 | 21 | public final class EndpointConfig { 22 | 23 | private final String url; 24 | private final String token; 25 | 26 | public EndpointConfig(String url, String token) { 27 | Checks.notBlank(token, "API Key"); 28 | Checks.notBlank(url, "Application URL"); 29 | this.url = url; 30 | this.token = token; 31 | } 32 | 33 | public String getUrl() { 34 | return url; 35 | } 36 | 37 | public String getToken() { 38 | return token; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/mattmalec/pterodactyl4j/utils/config/SessionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mattmalec.pterodactyl4j.utils.config; 18 | 19 | import com.mattmalec.pterodactyl4j.P4JInfo; 20 | import okhttp3.OkHttpClient; 21 | 22 | public final class SessionConfig { 23 | 24 | public static final String DEFAULT_USER_AGENT = "Pterodactyl4J (" + P4JInfo.VERSION + ")"; 25 | 26 | private final OkHttpClient httpClient; 27 | private final OkHttpClient webSocketClient; 28 | private String userAgent; 29 | 30 | public SessionConfig(OkHttpClient httpClient, OkHttpClient webSocketClient) { 31 | if (httpClient == null) httpClient = new OkHttpClient(); 32 | 33 | if (webSocketClient == null) webSocketClient = new OkHttpClient(); 34 | 35 | this.httpClient = httpClient; 36 | this.webSocketClient = webSocketClient; 37 | } 38 | 39 | public OkHttpClient getHttpClient() { 40 | return httpClient; 41 | } 42 | 43 | public OkHttpClient getWebSocketClient() { 44 | return webSocketClient; 45 | } 46 | 47 | public String getUserAgent() { 48 | return userAgent; 49 | } 50 | 51 | public void setUserAgent(String userAgent) { 52 | if (userAgent == null) userAgent = DEFAULT_USER_AGENT; 53 | this.userAgent = userAgent; 54 | } 55 | } 56 | --------------------------------------------------------------------------------