From 1b8825fcf5d365734bd6db7bf5df7c930d0cc72b Mon Sep 17 00:00:00 2001 From: Sascha Bartl Date: Sun, 23 Jun 2024 15:20:34 +0200 Subject: [PATCH] Feature: Node: setMaintanceMode (#74) * Node: setMaintanceMode * Node: setMaintanceMode - change property name * Node: setMaintanceMode - change property name / fix function naming * Node: hasMaintanceMode - fix docstring --- .../pterodactyl4j/application/entities/Node.java | 14 ++++++++++++-- .../application/entities/impl/CreateNodeImpl.java | 3 ++- .../application/entities/impl/EditNodeImpl.java | 6 +++++- .../application/entities/impl/NodeImpl.java | 4 ++-- .../application/managers/NodeAction.java | 4 +++- .../requests/action/AbstractNodeAction.java | 9 ++++++++- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/Node.java b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/Node.java index 4ac5af5..1dec6e8 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/Node.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/Node.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,17 @@ public interface Node extends ISnowflake { boolean isBehindProxy(); - boolean hasMaintanceMode(); + boolean isInMaintenanceMode(); + + /** + * @return {@code true} if the node is in maintenance mode + * + * @deprecated For spelling mistake only. Use {@link #isInMaintenanceMode()} instead + */ + @Deprecated + default boolean hasMaintanceMode() { + return isInMaintenanceMode(); + } default String getMemory() { return Long.toUnsignedString(getMemoryLong()); diff --git a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateNodeImpl.java b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateNodeImpl.java index 4bf3511..f2d40a8 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateNodeImpl.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/CreateNodeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,7 @@ protected RequestBody finalizeData() { json.put("daemon_listen", daemonListenPort); json.put("daemon_sftp", daemonSFTPPort); json.put("throttle", new JSONObject().put("enabled", throttle)); + json.put("maintenance_mode", maintenanceMode ? "1" : "0"); return getRequestBody(json); } } diff --git a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditNodeImpl.java b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditNodeImpl.java index 968d38b..a3db259 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditNodeImpl.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/EditNodeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,10 @@ protected RequestBody finalizeData() { json.put( "throttle", throttle == null ? new JSONObject().put("enabled", false) : new JSONObject().put("enabled", throttle)); + json.put( + "maintenance_mode", + maintenanceMode == null ? (node.isInMaintenanceMode() ? "1" : "0") : (maintenanceMode ? "1" : "0")); + return getRequestBody(json); } } diff --git a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/NodeImpl.java b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/NodeImpl.java index cd5f6e4..1a2b8a5 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/NodeImpl.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/application/entities/impl/NodeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,7 +89,7 @@ public boolean isBehindProxy() { } @Override - public boolean hasMaintanceMode() { + public boolean isInMaintenanceMode() { return json.getBoolean("maintenance_mode"); } diff --git a/src/main/java/com/mattmalec/pterodactyl4j/application/managers/NodeAction.java b/src/main/java/com/mattmalec/pterodactyl4j/application/managers/NodeAction.java index 781b8ef..e7e077e 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/application/managers/NodeAction.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/application/managers/NodeAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,4 +65,6 @@ default NodeAction setDiskSpaceOverallocate(long diskSpaceOverallocate) { NodeAction setThrottle(boolean throttle); NodeAction setScheme(boolean secure); + + NodeAction setMaintenanceMode(boolean maintenanceMode); } diff --git a/src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractNodeAction.java b/src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractNodeAction.java index aa02279..002bb69 100644 --- a/src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractNodeAction.java +++ b/src/main/java/com/mattmalec/pterodactyl4j/requests/action/AbstractNodeAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Matt Malec, and the Pterodactyl4J contributors + * Copyright 2021-2024 Matt Malec, and the Pterodactyl4J contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ public abstract class AbstractNodeAction extends PteroActionImpl implement protected String daemonListenPort; protected Boolean throttle; protected Boolean secure; + protected Boolean maintenanceMode; public AbstractNodeAction(PteroApplicationImpl impl, Route.CompiledRoute route) { super(impl.getP4J(), route, (response, request) -> new NodeImpl(response.getObject(), impl)); @@ -128,4 +129,10 @@ public NodeAction setScheme(boolean secure) { this.secure = secure; return this; } + + @Override + public NodeAction setMaintenanceMode(boolean maintenanceMode) { + this.maintenanceMode = maintenanceMode; + return this; + } }