mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 04:26:42 +00:00
Compare commits
2 Commits
2021.06-RC
...
ptero-upda
Author | SHA1 | Date | |
---|---|---|---|
8949ee75eb | |||
d88509bf11 |
19
.github/dependabot.yml
vendored
19
.github/dependabot.yml
vendored
@ -1,19 +0,0 @@
|
|||||||
# To get started with Dependabot version updates, you'll need to specify which
|
|
||||||
# package ecosystems to update and where the package manifests are located.
|
|
||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
|
|
||||||
# Maintain Maven Updates
|
|
||||||
- package-ecosystem: "maven" # See documentation for possible values
|
|
||||||
directory: "/" # Location of package manifests
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
|
|
||||||
# Maintain dependencies for GitHub Actions
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
12
.github/workflows/maven.yml
vendored
12
.github/workflows/maven.yml
vendored
@ -8,20 +8,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Java 11 Builds
|
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 1.8
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 11
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: mvn -B package --file pom.xml
|
run: mvn -B package --file pom.xml
|
||||||
|
|
||||||
# Java 16 Builds
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Set up JDK 16
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 16
|
|
||||||
- name: Build with Maven
|
|
||||||
run: mvn -B package --file pom.xml
|
|
||||||
|
13
.travis.yml
Normal file
13
.travis.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk11
|
||||||
|
- openjdk11
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- sshpass
|
||||||
|
script: mvn clean install
|
||||||
|
after_success:
|
||||||
|
- ./travis-upload.sh
|
@ -1,4 +1,4 @@
|
|||||||
# TotalFreedomMod [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/maven.yml) [](https://www.codacy.com/gh/AtlasMediaGroup/TotalFreedomMod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AtlasMediaGroup/TotalFreedomMod&utm_campaign=Badge_Grade) [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/codeql-analysis.yml)
|
# TotalFreedomMod [](https://travis-ci.com/AtlasMediaGroup/TotalFreedomMod) [](https://www.codacy.com/gh/AtlasMediaGroup/TotalFreedomMod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AtlasMediaGroup/TotalFreedomMod&utm_campaign=Badge_Grade)
|
||||||
|
|
||||||
TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](https://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server.
|
TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](https://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server.
|
||||||
|
|
||||||
@ -14,4 +14,4 @@ For information on our security policy and reporting an issue, please see [SECUR
|
|||||||
|
|
||||||
### Compiling
|
### Compiling
|
||||||
|
|
||||||
You need Maven to build. You'd also need to set the JDK version to Java 11 as that is the current standard as of now.
|
You need Maven to build. You'd also need to set the JDK version to Java 8 as that is the current standard as of now.
|
||||||
|
48
pom.xml
48
pom.xml
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>me.totalfreedom</groupId>
|
<groupId>me.totalfreedom</groupId>
|
||||||
<artifactId>TotalFreedomMod</artifactId>
|
<artifactId>TotalFreedomMod</artifactId>
|
||||||
<version>2021.06-RC01</version>
|
<version>2021.05</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -39,6 +39,11 @@
|
|||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>apache-snapshots</id>
|
||||||
|
<url>https://repository.apache.org/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
@ -109,6 +114,11 @@
|
|||||||
<id>ess-repo</id>
|
<id>ess-repo</id>
|
||||||
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>mattmalec-repo</id>
|
||||||
|
<url>https://repo.mattmalec.com/repository/releases</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -144,7 +154,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>1.8</version>
|
<version>2.2.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -163,9 +173,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.AtlasMediaGroup</groupId>
|
<groupId>com.github.TotalFreedomMC</groupId>
|
||||||
<artifactId>TF-LibsDisguises</artifactId>
|
<artifactId>TF-LibsDisguises</artifactId>
|
||||||
<version>5a340341b0</version>
|
<version>48f01cf2fe</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -186,21 +196,21 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.dv8tion</groupId>
|
<groupId>net.dv8tion</groupId>
|
||||||
<artifactId>JDA</artifactId>
|
<artifactId>JDA</artifactId>
|
||||||
<version>4.2.1_255</version>
|
<version>4.3.0_277</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.coreprotect</groupId>
|
<groupId>net.coreprotect</groupId>
|
||||||
<artifactId>coreprotect</artifactId>
|
<artifactId>coreprotect</artifactId>
|
||||||
<version>19.3</version>
|
<version>19.5</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
<artifactId>worldguard-bukkit</artifactId>
|
<artifactId>worldguard-bukkit</artifactId>
|
||||||
<version>7.0.4</version>
|
<version>7.0.5</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -259,12 +269,26 @@
|
|||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mattmalec</groupId>
|
||||||
|
<artifactId>Pterodactyl4J</artifactId>
|
||||||
|
<version>2.BETA_47</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.3.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>5.4.2</version>
|
<version>5.4.2</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.sisu</groupId>
|
<groupId>org.eclipse.sisu</groupId>
|
||||||
<artifactId>org.eclipse.sisu.inject</artifactId>
|
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||||
@ -299,7 +323,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>pl.project13.maven</groupId>
|
<groupId>pl.project13.maven</groupId>
|
||||||
<artifactId>git-commit-id-plugin</artifactId>
|
<artifactId>git-commit-id-plugin</artifactId>
|
||||||
<version>4.0.2</version>
|
<version>4.0.5</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>get-the-git-infos</id>
|
<id>get-the-git-infos</id>
|
||||||
@ -412,10 +436,12 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Shade -->
|
<!-- Shade -->
|
||||||
|
<!-- NOTE: This should only be temporary. This will need to be updated when a stable build comes out
|
||||||
|
that supports Java 16 -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.3.0-SNAPSHOT</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@ -427,8 +453,7 @@
|
|||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>io.papermc.lib</pattern>
|
<pattern>io.papermc.lib</pattern>
|
||||||
<shadedPattern>me.totalfreedom.totalfreedommod.paperlib
|
<shadedPattern>me.totalfreedom.totalfreedommod.paperlib</shadedPattern>
|
||||||
</shadedPattern> <!-- Replace this -->
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
@ -446,6 +471,7 @@
|
|||||||
<include>com.github.speedxx:Mojangson</include>
|
<include>com.github.speedxx:Mojangson</include>
|
||||||
<include>org.bstats:bstats-bukkit</include>
|
<include>org.bstats:bstats-bukkit</include>
|
||||||
<include>org.jetbrains:annotations</include>
|
<include>org.jetbrains:annotations</include>
|
||||||
|
<include>com.mattmalec:Pterodactyl4J</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -1,26 +1,30 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.mattmalec.pterodactyl4j.Permission;
|
||||||
import java.util.Arrays;
|
import com.mattmalec.pterodactyl4j.PowerAction;
|
||||||
import java.util.List;
|
import com.mattmalec.pterodactyl4j.PteroAction;
|
||||||
|
import com.mattmalec.pterodactyl4j.PteroBuilder;
|
||||||
|
import com.mattmalec.pterodactyl4j.application.entities.ApplicationUser;
|
||||||
|
import com.mattmalec.pterodactyl4j.application.entities.PteroApplication;
|
||||||
|
import com.mattmalec.pterodactyl4j.application.managers.UserAction;
|
||||||
|
import com.mattmalec.pterodactyl4j.client.entities.ClientServer;
|
||||||
|
import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser;
|
||||||
|
import com.mattmalec.pterodactyl4j.client.entities.PteroClient;
|
||||||
import joptsimple.internal.Strings;
|
import joptsimple.internal.Strings;
|
||||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.Response;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
public class Pterodactyl extends FreedomService
|
public class Pterodactyl extends FreedomService
|
||||||
{
|
{
|
||||||
|
|
||||||
public final String URL = ConfigEntry.PTERO_URL.getString();
|
public final String URL = ConfigEntry.PTERO_URL.getString();
|
||||||
private final String SERVER_KEY = ConfigEntry.PTERO_SERVER_KEY.getString();
|
|
||||||
private final String ADMIN_KEY = ConfigEntry.PTERO_ADMIN_KEY.getString();
|
private final String ADMIN_KEY = ConfigEntry.PTERO_ADMIN_KEY.getString();
|
||||||
private final List<String> SERVER_HEADERS = Arrays.asList("Accept:Application/vnd.pterodactyl.v1+json", "Content-Type:application/json", "Authorization:Bearer " + SERVER_KEY);
|
private final String CLIENT_KEY = ConfigEntry.PTERO_CLIENT_KEY.getString();
|
||||||
private final List<String> ADMIN_HEADERS = Arrays.asList("Accept:Application/vnd.pterodactyl.v1+json", "Content-Type:application/json", "Authorization:Bearer " + ADMIN_KEY);
|
private final String IDENTIFIER = ConfigEntry.PTERO_SERVER_UUID.getString();
|
||||||
|
private final PteroApplication adminAPI = PteroBuilder.createApplication(URL, ADMIN_KEY);
|
||||||
|
private final PteroClient clientAPI = PteroBuilder.createClient(URL, CLIENT_KEY);
|
||||||
|
private final ClientServer server = clientAPI.retrieveServerByIdentifier(IDENTIFIER).execute();
|
||||||
|
|
||||||
private boolean enabled = !Strings.isNullOrEmpty(URL);
|
private boolean enabled = !Strings.isNullOrEmpty(URL);
|
||||||
|
|
||||||
@ -43,163 +47,60 @@ public class Pterodactyl extends FreedomService
|
|||||||
|
|
||||||
if (!admin.isActive() || admin.getRank() != Rank.SENIOR_ADMIN)
|
if (!admin.isActive() || admin.getRank() != Rank.SENIOR_ADMIN)
|
||||||
{
|
{
|
||||||
FLog.debug("Disabling ptero acc");
|
FLog.debug("Disabling Pterodactyl account");
|
||||||
removeAccountFromServer(id);
|
removeAccountFromServer(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FLog.debug("Enabling ptero acc");
|
FLog.debug("Enabling Pterodactyl account");
|
||||||
addAccountToServer(id);
|
addAccountToServer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String createAccount(String username, String password)
|
public String createAccount(String username, String password)
|
||||||
{
|
{
|
||||||
JSONObject json = new JSONObject();
|
UserAction action = adminAPI.getUserManager().createUser()
|
||||||
json.put("username", username);
|
.setUserName(username)
|
||||||
json.put("password", password);
|
.setEmail(username.toLowerCase() + "@" + ConfigEntry.PTERO_DEFAULT_EMAIL_DOMAIN.getString())
|
||||||
json.put("email", username.toLowerCase() + "@" + ConfigEntry.PTERO_DEFAULT_EMAIL_DOMAIN.getString());
|
.setFirstName(username)
|
||||||
json.put("first_name", username);
|
.setLastName("\u200E") // Required - make it appear empty
|
||||||
json.put("last_name", "\u200E"); // required, so I made it appear empty
|
.setPassword(password);
|
||||||
|
|
||||||
Response response;
|
|
||||||
JSONObject jsonResponse;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = FUtil.sendRequest(URL + "/api/application/users", "POST", ADMIN_HEADERS, json.toJSONString());
|
|
||||||
jsonResponse = response.getJSONMessage();
|
|
||||||
}
|
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ((JSONObject)jsonResponse.get("attributes")).get("id").toString();
|
|
||||||
|
|
||||||
|
return action.execute().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteAccount(String id)
|
public void deleteAccount(String id)
|
||||||
{
|
{
|
||||||
JSONObject json = new JSONObject();
|
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
|
||||||
try
|
PteroAction<Void> action = adminAPI.getUserManager().deleteUser(username);
|
||||||
{
|
action.execute();
|
||||||
return FUtil.sendRequest(URL + "/api/application/users/" + id, "DELETE", ADMIN_HEADERS, json.toJSONString()).getCode() == 204;
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void addAccountToServer(String id)
|
public void addAccountToServer(String id)
|
||||||
{
|
{
|
||||||
String url = URL + "/api/client/servers/" + ConfigEntry.PTERO_SERVER_UUID.getString() + "/users";
|
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
|
||||||
|
String email = username.getEmail();
|
||||||
JSONObject userData = getUserData(id);
|
PteroAction<ClientServer> server = clientAPI.retrieveServerByIdentifier(IDENTIFIER);
|
||||||
if (userData == null)
|
server.execute().getSubuserManager().createUser()
|
||||||
{
|
.setEmail(email)
|
||||||
FLog.severe("The Pterodactyl user with the ID of " + id + " was not found");
|
.setPermissions(Permission.CONTROL_PERMISSIONS).execute();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("email", userData.get("email").toString());
|
|
||||||
json.put("permissions", Arrays.asList("control.console", "control.start", "control.restart", "control.stop", "control.kill"));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FUtil.sendRequest(url, "POST", SERVER_HEADERS, json.toJSONString());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAccountFromServer(String id)
|
public void removeAccountFromServer(String id)
|
||||||
{
|
{
|
||||||
JSONObject userData = getUserData(id);
|
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
|
||||||
if (userData == null)
|
PteroAction<ClientServer> server = clientAPI.retrieveServerByIdentifier(IDENTIFIER);
|
||||||
{
|
ClientSubuser clientSubuser = server.execute().getSubuser(username.getUUID()).retrieve().execute();
|
||||||
FLog.severe("The Pterodactyl user with the ID of " + id + " was not found");
|
server.execute().getSubuserManager().deleteUser(clientSubuser).execute();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String url = URL + "/api/client/servers/" + ConfigEntry.PTERO_SERVER_UUID.getString() + "/users/" + userData.get("uuid");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FUtil.sendRequest(url, "DELETE", SERVER_HEADERS, null);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getUserData(String id)
|
public void stopServer()
|
||||||
{
|
{
|
||||||
Response response;
|
clientAPI.setPower(server, PowerAction.STOP).execute();
|
||||||
JSONObject jsonResponse;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = FUtil.sendRequest(URL + "/api/application/users/" + id, "GET", ADMIN_HEADERS, null);
|
|
||||||
jsonResponse = response.getJSONMessage();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (JSONObject)jsonResponse.get("attributes");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// API patch function on users doesnt work rn, it throws 500 errors, so it's probably not written yet
|
public void restartServer()
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void setPassword(String id, String password)
|
|
||||||
{
|
{
|
||||||
JSONObject json = new JSONObject();
|
clientAPI.setPower(server, PowerAction.RESTART).execute();
|
||||||
json.put("password", password);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FUtil.sendRequest(URL + "/api/application/users/" + id, "PATCH", ADMIN_HEADERS, json.toJSONString());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
FLog.severe(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getURL()
|
|
||||||
{
|
|
||||||
return URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServerKey()
|
|
||||||
{
|
|
||||||
return SERVER_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAdminKey()
|
|
||||||
{
|
|
||||||
return ADMIN_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getServerHeaders()
|
|
||||||
{
|
|
||||||
return SERVER_HEADERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAdminHeaders()
|
|
||||||
{
|
|
||||||
return ADMIN_HEADERS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled()
|
public boolean isEnabled()
|
||||||
|
@ -77,26 +77,13 @@ public class Command_cage extends FreedomCommand
|
|||||||
}
|
}
|
||||||
case "block":
|
case "block":
|
||||||
{
|
{
|
||||||
if (args.length >= 3)
|
if (Material.matchMaterial(args[2]) != null)
|
||||||
{
|
{
|
||||||
// Checks the validity of the Material and checks if it's a block.
|
outerMaterial = Material.matchMaterial(args[2]);
|
||||||
// This is incredibly inefficient, as Spigot's isBlock() method in Material is an actual
|
break;
|
||||||
// nightmare of switch-cases.
|
|
||||||
if (Material.matchMaterial(args[2]) != null && Material.matchMaterial(args[2]).isBlock())
|
|
||||||
{
|
|
||||||
outerMaterial = Material.matchMaterial(args[2]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg("Invalid block!", ChatColor.RED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
msg("Invalid block!", ChatColor.RED);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Clears the chat.", usage = "/<command>", aliases = "cc")
|
@CommandParameters(description = "Clears the chat.", usage = "/<command>", aliases = "cc")
|
||||||
public class Command_cleanchat extends FreedomCommand
|
public class Command_clearchat extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,4 +27,4 @@ public class Command_cleanchat extends FreedomCommand
|
|||||||
FUtil.adminAction(sender.getName(), "Cleared chat", true);
|
FUtil.adminAction(sender.getName(), "Cleared chat", true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,11 +17,9 @@ import org.bukkit.entity.Player;
|
|||||||
@CommandParameters(description = "Manage your Pterodactyl panel account", usage = "/<command> <create | delete>")
|
@CommandParameters(description = "Manage your Pterodactyl panel account", usage = "/<command> <create | delete>")
|
||||||
public class Command_panel extends FreedomCommand
|
public class Command_panel extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!plugin.ptero.isEnabled())
|
if (!plugin.ptero.isEnabled())
|
||||||
{
|
{
|
||||||
msg("Pterodactyl integration is currently disabled.", ChatColor.RED);
|
msg("Pterodactyl integration is currently disabled.", ChatColor.RED);
|
||||||
@ -32,7 +30,7 @@ public class Command_panel extends FreedomCommand
|
|||||||
|
|
||||||
if (playerData.getDiscordID() == null)
|
if (playerData.getDiscordID() == null)
|
||||||
{
|
{
|
||||||
msg("You must have a linked discord account.", ChatColor.RED);
|
msg("You must have a linked Discord account.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,13 +61,11 @@ public class Command_panel extends FreedomCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.ptero.addAccountToServer(id);
|
plugin.ptero.addAccountToServer(id);
|
||||||
|
|
||||||
admin.setPteroID(id);
|
admin.setPteroID(id);
|
||||||
plugin.al.save(admin);
|
plugin.al.save(admin);
|
||||||
plugin.al.updateTables();
|
plugin.al.updateTables();
|
||||||
|
|
||||||
plugin.dc.sendPteroInfo(playerData, username, password);
|
plugin.dc.sendPteroInfo(playerData, username, password);
|
||||||
msg("Successfully created your Pterodactyl account. Check your DMs from " + plugin.dc.formatBotTag() + " on discord to get your credentials.", ChatColor.GREEN);
|
msg("Successfully created your Pterodactyl account. Check your DMs from " + plugin.dc.formatBotTag() + " on Discord to get your credentials.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("delete"))
|
else if (args[0].equalsIgnoreCase("delete"))
|
||||||
@ -83,18 +79,10 @@ public class Command_panel extends FreedomCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean deleted = plugin.ptero.deleteAccount(admin.getPteroID());
|
plugin.ptero.deleteAccount(admin.getPteroID());
|
||||||
|
|
||||||
if (!deleted)
|
|
||||||
{
|
|
||||||
msg("Failed to delete your Pterodactyl account.", ChatColor.RED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
admin.setPteroID(null);
|
admin.setPteroID(null);
|
||||||
plugin.al.save(admin);
|
plugin.al.save(admin);
|
||||||
plugin.al.updateTables();
|
plugin.al.updateTables();
|
||||||
|
|
||||||
msg("Successfully deleted your Pterodactyl account.", ChatColor.GREEN);
|
msg("Successfully deleted your Pterodactyl account.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Restart the server", usage = "/<command> [reason]")
|
||||||
|
public class Command_restart extends FreedomCommand
|
||||||
|
{
|
||||||
|
private static final Map<CommandSender, String> RESTART_CONFIRM = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (!plugin.ptero.isEnabled())
|
||||||
|
{
|
||||||
|
msg("Pterodactyl integration is currently disabled.", ChatColor.RED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String reason = "Server is restarting!";
|
||||||
|
|
||||||
|
if (args.length != 0)
|
||||||
|
{
|
||||||
|
reason = StringUtils.join(args, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.getName().equals("CONSOLE"))
|
||||||
|
{
|
||||||
|
restart(reason);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (RESTART_CONFIRM.containsKey(sender))
|
||||||
|
{
|
||||||
|
restart(RESTART_CONFIRM.get(sender));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg("Warning: You're about to restart the server. Type /restart again to confirm you want to do this.");
|
||||||
|
|
||||||
|
RESTART_CONFIRM.put(sender, reason);
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (RESTART_CONFIRM.containsKey(sender))
|
||||||
|
{
|
||||||
|
RESTART_CONFIRM.remove(sender);
|
||||||
|
msg("Restart request expired.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 15 * 20);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restart(String reason)
|
||||||
|
{
|
||||||
|
FUtil.bcastMsg("Server is restarting!", ChatColor.LIGHT_PURPLE);
|
||||||
|
|
||||||
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
player.kickPlayer(ChatColor.LIGHT_PURPLE + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
RESTART_CONFIRM.remove(sender);
|
||||||
|
plugin.ptero.restartServer();
|
||||||
|
}
|
||||||
|
}
|
@ -1,97 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
|
||||||
@CommandParameters(description = "Get the seed of the world you are currently in.", usage = "/seed [world]")
|
|
||||||
public class Command_seed extends FreedomCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
World world;
|
|
||||||
|
|
||||||
if (args.length > 0)
|
|
||||||
{
|
|
||||||
world = server.getWorld(args[0]);
|
|
||||||
if (world == null)
|
|
||||||
{
|
|
||||||
msg("That world could not be found", ChatColor.RED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If the sender is a Player, use that world. Otherwise, use the overworld as a fallback.
|
|
||||||
if (!senderIsConsole)
|
|
||||||
{
|
|
||||||
world = playerSender.getWorld();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
world = server.getWorlds().get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the sender is not a Player, use the usual msg method to
|
|
||||||
if (senderIsConsole)
|
|
||||||
{
|
|
||||||
msg("Seed: [" + ChatColor.GREEN + world.getSeed() + ChatColor.WHITE + "]", ChatColor.WHITE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Gets the seed for later uses
|
|
||||||
String seed = String.valueOf(world.getSeed());
|
|
||||||
|
|
||||||
// This is a really stupid hack to get things to play nicely, but it works so I don't give a damn
|
|
||||||
BaseComponent[] components = {new TranslatableComponent("chat.copy.click")};
|
|
||||||
TextComponent seedAsComponent = new TextComponent(seed);
|
|
||||||
|
|
||||||
// Style the message like in vanilla Minecraft.
|
|
||||||
seedAsComponent.setColor(ChatColor.GREEN.asBungee());
|
|
||||||
seedAsComponent.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, seed));
|
|
||||||
seedAsComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(components)));
|
|
||||||
|
|
||||||
// Enclose the seed with brackets
|
|
||||||
TextComponent seedString = new TextComponent("[");
|
|
||||||
seedString.addExtra(seedAsComponent);
|
|
||||||
seedString.addExtra("]");
|
|
||||||
|
|
||||||
// Send the message to the player.
|
|
||||||
TranslatableComponent response = new TranslatableComponent("commands.seed.success", seedString);
|
|
||||||
playerSender.spigot().sendMessage(response);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
// Returns a list of worlds on the server and returns it
|
|
||||||
List<String> worlds = new ArrayList<>();
|
|
||||||
for (World world : server.getWorlds())
|
|
||||||
{
|
|
||||||
worlds.add(world.getName());
|
|
||||||
}
|
|
||||||
return worlds;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,7 +20,6 @@ public class Command_stop extends FreedomCommand
|
|||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
|
|
||||||
String reason = "Server is going offline, come back in about 20 seconds.";
|
String reason = "Server is going offline, come back in about 20 seconds.";
|
||||||
|
|
||||||
if (args.length != 0)
|
if (args.length != 0)
|
||||||
@ -39,7 +38,6 @@ public class Command_stop extends FreedomCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg("Warning: You're about to stop the server. Type /stop again to confirm you want to do this.");
|
msg("Warning: You're about to stop the server. Type /stop again to confirm you want to do this.");
|
||||||
|
|
||||||
STOP_CONFIRM.put(sender, reason);
|
STOP_CONFIRM.put(sender, reason);
|
||||||
@ -69,6 +67,13 @@ public class Command_stop extends FreedomCommand
|
|||||||
|
|
||||||
STOP_CONFIRM.remove(sender);
|
STOP_CONFIRM.remove(sender);
|
||||||
|
|
||||||
server.shutdown();
|
if (plugin.ptero.isEnabled())
|
||||||
|
{
|
||||||
|
plugin.ptero.stopServer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public enum ConfigEntry
|
|||||||
PTERO_DEFAULT_EMAIL_DOMAIN(String.class, "ptero.default_email_domain"),
|
PTERO_DEFAULT_EMAIL_DOMAIN(String.class, "ptero.default_email_domain"),
|
||||||
PTERO_SERVER_UUID(String.class, "ptero.server_uuid"),
|
PTERO_SERVER_UUID(String.class, "ptero.server_uuid"),
|
||||||
PTERO_ADMIN_KEY(String.class, "ptero.admin_key"),
|
PTERO_ADMIN_KEY(String.class, "ptero.admin_key"),
|
||||||
PTERO_SERVER_KEY(String.class, "ptero.server_key"),
|
PTERO_CLIENT_KEY(String.class, "ptero.client_key"),
|
||||||
//
|
//
|
||||||
SHOP_ENABLED(Boolean.class, "shop.enabled"),
|
SHOP_ENABLED(Boolean.class, "shop.enabled"),
|
||||||
SHOP_TITLE(String.class, "shop.title"),
|
SHOP_TITLE(String.class, "shop.title"),
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package me.totalfreedom.totalfreedommod.player;
|
package me.totalfreedom.totalfreedommod.player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.caging.CageData;
|
import me.totalfreedom.totalfreedommod.caging.CageData;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
@ -14,12 +16,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FPlayer
|
public class FPlayer
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final long AUTO_PURGE_TICKS = 5L * 60L * 20L;
|
public static final long AUTO_PURGE_TICKS = 5L * 60L * 20L;
|
||||||
|
|
||||||
|
|
||||||
@ -249,7 +247,7 @@ public class FPlayer
|
|||||||
public void startArrowShooter(TotalFreedomMod plugin)
|
public void startArrowShooter(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
this.stopArrowShooter();
|
this.stopArrowShooter();
|
||||||
this.mp44ScheduleTask = new ArrowShooter(getPlayer()).runTaskTimer(plugin, 1L, 1L);
|
this.mp44ScheduleTask = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
|
||||||
this.mp44Firing = true;
|
this.mp44Firing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,11 +709,8 @@ public class FPlayer
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (player != null)
|
Arrow shot = player.launchProjectile(Arrow.class);
|
||||||
{
|
shot.setVelocity(shot.getVelocity().multiply(2.0));
|
||||||
Arrow shot = player.launchProjectile(Arrow.class);
|
|
||||||
shot.setVelocity(shot.getVelocity().multiply(2.0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -85,18 +85,23 @@ discord:
|
|||||||
# Owner role ID
|
# Owner role ID
|
||||||
server_owner_role_id: ''
|
server_owner_role_id: ''
|
||||||
|
|
||||||
# Pterodactyl
|
# Pterodactyl (requires Discord verification to be enabled)
|
||||||
ptero:
|
ptero:
|
||||||
# URL - do not leave a trailing forward slash
|
# URL - do not leave a trailing forward slash
|
||||||
url: ''
|
url: ''
|
||||||
# The default email domain used to set email addresses for new users - do not include the @
|
# The default email domain used to set email addresses for new users - do not include the @
|
||||||
default_email_domain: 'example.com'
|
default_email_domain: 'example.com'
|
||||||
# Server UUID
|
# Long Server UUID (for example: abf9a712-6c5a-4504-b4bc-37f1061b8801)
|
||||||
|
# Do NOT give the short Server UUID
|
||||||
server_uuid: ''
|
server_uuid: ''
|
||||||
# Admin panel API key
|
# Admin panel API key
|
||||||
|
# Create this key by going to Settings > Application API > Create New
|
||||||
|
# Make sure you give it Users and Servers permissions
|
||||||
admin_key: ''
|
admin_key: ''
|
||||||
# Server API key
|
# Client API key
|
||||||
server_key: ''
|
# Create a new user and add them as a subuser to the server with all control privileges.
|
||||||
|
# Then, login to the new user account and go to User Settings. Click on API Credentials and create a new one.
|
||||||
|
client_key: ''
|
||||||
|
|
||||||
# The shop
|
# The shop
|
||||||
shop:
|
shop:
|
||||||
|
Reference in New Issue
Block a user