Create FlexConnect project
This commit is contained in:
commit
f3ee582969
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
bin/
|
||||||
|
target/
|
||||||
|
settings.json
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.factorypath
|
||||||
|
*.iml
|
||||||
|
*.settings/
|
||||||
|
.vscode/
|
67
pom.xml
Normal file
67
pom.xml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>fi.flexplex</groupId>
|
||||||
|
<artifactId>connect</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<name>flexconnect</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>FlexConnect</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>16</source>
|
||||||
|
<target>16</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>paper</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
81
src/main/java/fi/flexplex/connect/FlexConnect.java
Normal file
81
src/main/java/fi/flexplex/connect/FlexConnect.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package fi.flexplex.connect;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public final class FlexConnect extends JavaPlugin {
|
||||||
|
|
||||||
|
private String token = "";
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
|
||||||
|
// Plugin own configs
|
||||||
|
this.saveDefaultConfig();
|
||||||
|
this.token = this.getConfig().getString("token");
|
||||||
|
if (this.token.equals("default")) {
|
||||||
|
this.getLogger().warning("Token for FlexPlex server network has not been set into plugins config file. Please request token from FlexPlex staff members if you don't already have one!");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean configsModified = false;
|
||||||
|
|
||||||
|
// Check online mode
|
||||||
|
if (this.getServer().getOnlineMode()) {
|
||||||
|
final Properties properties = new Properties();
|
||||||
|
try {
|
||||||
|
properties.load(new FileInputStream("server.properties"));
|
||||||
|
properties.setProperty("online-mode", "false");
|
||||||
|
properties.store(new FileOutputStream("server.properties"), null);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
this.getLogger().warning("Automatic changes has been made to server.properties file.");
|
||||||
|
configsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check paper config
|
||||||
|
boolean paperConfigModified = false;
|
||||||
|
final YamlConfiguration paperConfig = this.getServer().spigot().getPaperConfig();
|
||||||
|
if (!paperConfig.getBoolean("settings.velocity-support.enabled")) {
|
||||||
|
paperConfig.set("settings.velocity-support.enabled", true);
|
||||||
|
paperConfigModified = true;
|
||||||
|
}
|
||||||
|
if (!paperConfig.getBoolean("settings.velocity-support.enabled")) {
|
||||||
|
paperConfig.set("settings.velocity-support.online-mode", true);
|
||||||
|
paperConfigModified = true;
|
||||||
|
}
|
||||||
|
if (!paperConfig.getString("settings.velocity-support.secret").equals("flexplex")) {
|
||||||
|
paperConfig.set("settings.velocity-support.secret", "flexplex");
|
||||||
|
paperConfigModified = true;
|
||||||
|
}
|
||||||
|
if (paperConfigModified) {
|
||||||
|
try {
|
||||||
|
paperConfig.save("paper.yml");
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
this.getLogger().warning("Automatic changes has been made to paper.yml config file.");
|
||||||
|
configsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions if configs were modified
|
||||||
|
if (configsModified) {
|
||||||
|
this.getLogger().warning("Changes has been made to config files. Server will now shutdown automatically.");
|
||||||
|
this.getServer().shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register listener
|
||||||
|
this.getServer().getPluginManager().registerEvents(new FlexConnectListener(this), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/main/java/fi/flexplex/connect/FlexConnectListener.java
Normal file
30
src/main/java/fi/flexplex/connect/FlexConnectListener.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package fi.flexplex.connect;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
|
||||||
|
public final class FlexConnectListener implements Listener {
|
||||||
|
|
||||||
|
private final FlexConnect flexConnect;
|
||||||
|
|
||||||
|
public FlexConnectListener(final FlexConnect flexConnect) {
|
||||||
|
this.flexConnect = flexConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
||||||
|
// Authenticate players
|
||||||
|
for (final ProfileProperty property : event.getPlayerProfile().getProperties()) {
|
||||||
|
if (property.getName().equals("flexplex-token") && property.getValue().equals(flexConnect.getToken())) {
|
||||||
|
// Authentication success
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Authentication failed
|
||||||
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Access denied");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
src/main/resources/config.yml
Normal file
1
src/main/resources/config.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
token: "default"
|
7
src/main/resources/plugin.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
name: FlexConnect
|
||||||
|
version: 1.0
|
||||||
|
api-version: 1.13
|
||||||
|
description: Connect's your server to FlexPlex network.
|
||||||
|
author: FlexPlex
|
||||||
|
website: https://flexplex.fi
|
||||||
|
main: fi.flexplex.connect.FlexConnect
|
Loading…
Reference in New Issue
Block a user