Initial project for 1.5.2 branch
This commit is contained in:
128
.gitignore
vendored
128
.gitignore
vendored
@ -1,98 +1,38 @@
|
|||||||
# ---> JetBrains
|
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/**/usage.statistics.xml
|
|
||||||
.idea/**/dictionaries
|
|
||||||
.idea/**/shelf
|
|
||||||
|
|
||||||
# AWS User-specific
|
|
||||||
.idea/**/aws.xml
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
.idea/**/contentModel.xml
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
.idea/**/dataSources/
|
|
||||||
.idea/**/dataSources.ids
|
|
||||||
.idea/**/dataSources.local.xml
|
|
||||||
.idea/**/sqlDataSources.xml
|
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
.idea/**/dbnavigator.xml
|
|
||||||
|
|
||||||
# Gradle
|
|
||||||
.idea/**/gradle.xml
|
|
||||||
.idea/**/libraries
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
cmake-build-*/
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
.idea/replstate.xml
|
|
||||||
|
|
||||||
# SonarLint plugin
|
|
||||||
.idea/sonarlint/
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
.idea/httpRequests
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
.idea/caches/build_file_checksums.ser
|
|
||||||
|
|
||||||
# ---> Maven
|
|
||||||
target/
|
target/
|
||||||
pom.xml.tag
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
pom.xml.releaseBackup
|
!**/src/main/**/target/
|
||||||
pom.xml.versionsBackup
|
!**/src/test/**/target/
|
||||||
pom.xml.next
|
|
||||||
release.properties
|
|
||||||
dependency-reduced-pom.xml
|
|
||||||
buildNumber.properties
|
|
||||||
.mvn/timing.properties
|
|
||||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
# Eclipse m2e generated files
|
### IntelliJ IDEA ###
|
||||||
# Eclipse Core
|
.idea/modules.xml
|
||||||
.project
|
.idea/jarRepositories.xml
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
19
.idea/misc.xml
generated
Normal file
19
.idea/misc.xml
generated
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<list size="1">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||||
|
</list>
|
||||||
|
</component>
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -1,3 +1,5 @@
|
|||||||
# FMCServer
|
# FMCServer - ForeverMC 服务器插件
|
||||||
|
|
||||||
ForeverMC 服务器状态报告插件
|
适用版本:1.5.2
|
||||||
|
|
||||||
|
详细说明请看主分支 README.md
|
||||||
|
|||||||
7
lib/install.sh
Normal file
7
lib/install.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
mvn install:install-file \
|
||||||
|
-Dfile=./mcpc.jar \
|
||||||
|
-DgroupId=local \
|
||||||
|
-DartifactId=fmc-mcpc \
|
||||||
|
-Dversion=1.5.2 \
|
||||||
|
-Dpackaging=jar \
|
||||||
|
-DgeneratePom=true
|
||||||
BIN
lib/mcpc.jar
Normal file
BIN
lib/mcpc.jar
Normal file
Binary file not shown.
61
pom.xml
Normal file
61
pom.xml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>cn.forevermc.server.bukkit</groupId>
|
||||||
|
<artifactId>FMCServer</artifactId>
|
||||||
|
<version>0.0.1+1.5.2</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>cn.forevermc.server.mcpc.FMCServer</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.10.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>local</groupId>
|
||||||
|
<artifactId>fmc-mcpc</artifactId>
|
||||||
|
<version>1.5.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.34</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
90
src/main/java/cn/forevermc/server/mcpc/FMCServer.java
Normal file
90
src/main/java/cn/forevermc/server/mcpc/FMCServer.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package cn.forevermc.server.mcpc;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.command.DebugCommand;
|
||||||
|
import cn.forevermc.server.mcpc.command.StaffCommand;
|
||||||
|
import cn.forevermc.server.mcpc.event.DebugEvent;
|
||||||
|
import cn.forevermc.server.mcpc.service.ReportService;
|
||||||
|
import cn.forevermc.server.mcpc.util.Util;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ForeverMC 服务器状态报告插件
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2022-11-14 11:05
|
||||||
|
*/
|
||||||
|
public class FMCServer extends JavaPlugin {
|
||||||
|
|
||||||
|
public static final Gson GSON = new Gson();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static FileConfiguration configuration;
|
||||||
|
|
||||||
|
private static Logger log;
|
||||||
|
private BukkitTask statusServiceTask;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
log = getLogger();
|
||||||
|
configuration = getConfig();
|
||||||
|
defConfig();
|
||||||
|
|
||||||
|
{
|
||||||
|
// config
|
||||||
|
log.info("debug: " + configuration.getBoolean("debug.enable"));
|
||||||
|
log.info("debug.staff: " + configuration.getStringList("debug.staff"));
|
||||||
|
log.info("report: " + configuration.getBoolean("report.enable"));
|
||||||
|
log.info("report.id: " + configuration.getString("report.id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
getCommand("debug").setExecutor(new DebugCommand(this));
|
||||||
|
getCommand("staff").setExecutor(new StaffCommand(this));
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new DebugEvent(), this);
|
||||||
|
|
||||||
|
if (configuration.getBoolean("report.enable")) {
|
||||||
|
statusServiceTask = new ReportService(FMCServer.this).runTaskTimerAsynchronously(FMCServer.this, 0, 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (statusServiceTask != null) {
|
||||||
|
statusServiceTask.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadConfig() {
|
||||||
|
super.reloadConfig();
|
||||||
|
configuration = getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(Level level, String msg) {
|
||||||
|
log.log(level, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 默认配置 */
|
||||||
|
private void defConfig() {
|
||||||
|
configuration.addDefault("debug.enable", false);
|
||||||
|
configuration.addDefault("debug.staff", new String[0]);
|
||||||
|
configuration.addDefault("report.enable", false);
|
||||||
|
configuration.addDefault("report.id", UUID.randomUUID().toString());
|
||||||
|
configuration.addDefault("report.api.info", "http://localhost:8091/fmc/server/info");
|
||||||
|
configuration.addDefault("report.api.status", "http://localhost:8091/fmc/server/status");
|
||||||
|
configuration.addDefault("report.token", "");
|
||||||
|
configuration.addDefault("report.name", "FMCServer#" + Util.randomString(8));
|
||||||
|
configuration.addDefault("report.clientURL", "");
|
||||||
|
configuration.addDefault("report.ip", "");
|
||||||
|
configuration.options().copyDefaults(true);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
package cn.forevermc.server.mcpc.bean;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器状态
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-06 20:38
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ServerStatusRequest {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private ServerStatus status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2021-12-02 19:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class ServerStatus {
|
||||||
|
|
||||||
|
/** true 为维护中 */
|
||||||
|
private boolean isDebugging;
|
||||||
|
|
||||||
|
/** TPS */
|
||||||
|
private double tps;
|
||||||
|
|
||||||
|
/** 报告时间 */
|
||||||
|
private long reportAt;
|
||||||
|
|
||||||
|
/** JVM 状态 */
|
||||||
|
private JVM jvm = new JVM();
|
||||||
|
|
||||||
|
/** 在线列表 */
|
||||||
|
private List<String> onlineList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 TPS 取平均
|
||||||
|
*
|
||||||
|
* @param tpsList TPS 列表
|
||||||
|
*/
|
||||||
|
public void setTps(double[] tpsList) {
|
||||||
|
double sum = 0;
|
||||||
|
for (int i = 0; i < tpsList.length; i++) {
|
||||||
|
sum += tpsList[i];
|
||||||
|
}
|
||||||
|
tps = sum / tpsList.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JVM 状态
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2022-11-11 14:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class JVM {
|
||||||
|
|
||||||
|
/** CPU 已使用 */
|
||||||
|
private double cpuUsed;
|
||||||
|
|
||||||
|
/** 内存状态 */
|
||||||
|
private Memory memory = new Memory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存状态
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2022-11-15 09:54
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class Memory {
|
||||||
|
|
||||||
|
/** 已使用 */
|
||||||
|
private long used;
|
||||||
|
|
||||||
|
/** 已申请 */
|
||||||
|
private long committed;
|
||||||
|
|
||||||
|
/** 最大内存 */
|
||||||
|
private long max;
|
||||||
|
|
||||||
|
/** JVM 名称 */
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
111
src/main/java/cn/forevermc/server/mcpc/command/DebugCommand.java
Normal file
111
src/main/java/cn/forevermc/server/mcpc/command/DebugCommand.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package cn.forevermc.server.mcpc.command;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import cn.forevermc.server.mcpc.util.Util;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维护模式
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 12:44
|
||||||
|
*/
|
||||||
|
public class DebugCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指令动作
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 20:15
|
||||||
|
*/
|
||||||
|
private enum Action {
|
||||||
|
|
||||||
|
/** 启用 */
|
||||||
|
TRUE,
|
||||||
|
|
||||||
|
/** 禁用 */
|
||||||
|
FALSE,
|
||||||
|
|
||||||
|
/** 当前状态 */
|
||||||
|
STATUS
|
||||||
|
}
|
||||||
|
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final List<String> actionList;
|
||||||
|
|
||||||
|
public DebugCommand(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
actionList = new ArrayList<>();
|
||||||
|
for (Action action : Action.values()) {
|
||||||
|
actionList.add(action.toString().toLowerCase());
|
||||||
|
}
|
||||||
|
plugin.getCommand("debug").setTabCompleter(new TabCompleter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
return actionList;
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
FileConfiguration config = FMCServer.getConfiguration();
|
||||||
|
|
||||||
|
boolean isEnable = config.getBoolean("debug.enable");
|
||||||
|
Action action;
|
||||||
|
if (args.length == 1) {
|
||||||
|
// 含动作参数
|
||||||
|
action = Util.enumValueOf(Action.class, args[0]);
|
||||||
|
if (action == Action.TRUE) {
|
||||||
|
isEnable = true;
|
||||||
|
}
|
||||||
|
if (action == Action.FALSE) {
|
||||||
|
isEnable = false;
|
||||||
|
}
|
||||||
|
if (action == Action.STATUS) {
|
||||||
|
if (isEnable) {
|
||||||
|
Util.returnMsg(sender, Level.INFO, "当前维护模式:启用");
|
||||||
|
} else {
|
||||||
|
Util.returnMsg(sender, Level.INFO, "当前维护模式:禁用");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 直接切换
|
||||||
|
isEnable = !isEnable;
|
||||||
|
}
|
||||||
|
config.set("debug.enable", isEnable);
|
||||||
|
if (isEnable) {
|
||||||
|
Player[] players = plugin.getServer().getOnlinePlayers();
|
||||||
|
List<String> staffList = config.getStringList("debug.staff");
|
||||||
|
// 踢出非维护人员
|
||||||
|
for (Player player : players) {
|
||||||
|
if (!staffList.contains(player.getName())) {
|
||||||
|
player.kickPlayer("服务器正在维护,请稍后重试");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Util.returnMsg(sender, Level.INFO, "已启用维护模式");
|
||||||
|
} else {
|
||||||
|
Util.returnMsg(sender, Level.INFO, "已禁用维护模式");
|
||||||
|
}
|
||||||
|
plugin.saveConfig();
|
||||||
|
plugin.reloadConfig();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
104
src/main/java/cn/forevermc/server/mcpc/command/StaffCommand.java
Normal file
104
src/main/java/cn/forevermc/server/mcpc/command/StaffCommand.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package cn.forevermc.server.mcpc.command;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import cn.forevermc.server.mcpc.util.Util;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维护人员操作
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 12:44
|
||||||
|
*/
|
||||||
|
public class StaffCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指令动作
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 14:29
|
||||||
|
*/
|
||||||
|
private enum Action {
|
||||||
|
|
||||||
|
/** 添加 */
|
||||||
|
ADD,
|
||||||
|
|
||||||
|
/** 移除 */
|
||||||
|
REMOVE,
|
||||||
|
|
||||||
|
/** 列表 */
|
||||||
|
LIST
|
||||||
|
}
|
||||||
|
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final List<String> actionList;
|
||||||
|
|
||||||
|
public StaffCommand(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
actionList = new ArrayList<>();
|
||||||
|
for (Action action : Action.values()) {
|
||||||
|
actionList.add(action.toString().toLowerCase());
|
||||||
|
}
|
||||||
|
plugin.getCommand("staff").setTabCompleter(new TabCompleter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
return actionList;
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
FileConfiguration config = FMCServer.getConfiguration();
|
||||||
|
Action action = Util.enumValueOf(Action.class, args[0]);
|
||||||
|
if (action == null) {
|
||||||
|
Util.returnMsg(sender, Level.WARNING, "使用方式: /staff [add|remove|list] <value>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Set<String> staffSet = new HashSet<>(config.getStringList("debug.staff"));
|
||||||
|
if (action == Action.LIST) {
|
||||||
|
Util.returnMsg(sender, Level.INFO, "维护人员列表: " + staffSet);
|
||||||
|
} else {
|
||||||
|
if (args.length < 2) {
|
||||||
|
Util.returnMsg(sender, Level.WARNING, "使用方式: /staff [add|remove|list] <value>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String value = args[1];
|
||||||
|
if (value.isEmpty()) {
|
||||||
|
Util.returnMsg(sender, Level.WARNING, "请输入维护人员 ID");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (action) {
|
||||||
|
case ADD:
|
||||||
|
staffSet.add(value);
|
||||||
|
Util.returnMsg(sender, Level.INFO, String.format("已添加 %s 维护人员", value));
|
||||||
|
break;
|
||||||
|
case REMOVE:
|
||||||
|
staffSet.remove(value);
|
||||||
|
Util.returnMsg(sender, Level.INFO, String.format("已移除 %s 维护人员", value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config.set("debug.staff", staffSet.toArray(new String[0]));
|
||||||
|
plugin.saveConfig();
|
||||||
|
plugin.reloadConfig();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/main/java/cn/forevermc/server/mcpc/event/DebugEvent.java
Normal file
30
src/main/java/cn/forevermc/server/mcpc/event/DebugEvent.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cn.forevermc.server.mcpc.event;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试事件
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 12:35
|
||||||
|
*/
|
||||||
|
public class DebugEvent implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
FileConfiguration config = FMCServer.getConfiguration();
|
||||||
|
if (!config.getBoolean("debug.enable")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> staff = config.getStringList("debug.staff");
|
||||||
|
if (!staff.contains(event.getPlayer().getName())) {
|
||||||
|
event.getPlayer().kickPlayer("服务器正在维护,请稍后重试");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,159 @@
|
|||||||
|
package cn.forevermc.server.mcpc.service;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import cn.forevermc.server.mcpc.bean.ServerStatusRequest;
|
||||||
|
import cn.forevermc.server.mcpc.util.HTTP;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.MemoryMXBean;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态报告服务
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2022-11-11 14:38
|
||||||
|
*/
|
||||||
|
public class ReportService extends BukkitRunnable {
|
||||||
|
|
||||||
|
private final Server server = Bukkit.getServer();
|
||||||
|
private final ServerStatusRequest request = new ServerStatusRequest();
|
||||||
|
private final MemoryMXBean jvmMemory = ManagementFactory.getMemoryMXBean();
|
||||||
|
private final OperatingSystemMXBean operatingSystemMXBean;
|
||||||
|
|
||||||
|
private final String api;
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final double[] tpsList = new double[9];
|
||||||
|
|
||||||
|
/** 失败时间,用于失败时任务执行周期将会更长 */
|
||||||
|
private long failAt = -1;
|
||||||
|
|
||||||
|
public ReportService(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
api = FMCServer.getConfiguration().getString("report.api.status");
|
||||||
|
operatingSystemMXBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
|
||||||
|
|
||||||
|
if (api == null || api.isEmpty()) {
|
||||||
|
FMCServer.log(Level.WARNING, "start report task fail because of not found report.api.status in configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request.setId(plugin.getConfig().getString("report.id"));
|
||||||
|
request.setStatus(new ServerStatusRequest.ServerStatus());
|
||||||
|
|
||||||
|
// TPS 计算
|
||||||
|
server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
|
|
||||||
|
private int ticks;
|
||||||
|
private int tpsI;
|
||||||
|
private long cs;
|
||||||
|
private double tps;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long s = System.currentTimeMillis() / 1000;
|
||||||
|
if (cs == s) {
|
||||||
|
ticks++;
|
||||||
|
} else {
|
||||||
|
cs = s;
|
||||||
|
tpsI++;
|
||||||
|
tpsList[tpsI % tpsList.length] = tps = tps == 0 ? ticks : ((tps + ticks) / 2);
|
||||||
|
ticks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 报告基本信息 */
|
||||||
|
private void sendInfo() throws Exception {
|
||||||
|
FileConfiguration config = FMCServer.getConfiguration();
|
||||||
|
String api = config.getString("report.api.info");
|
||||||
|
if (api == null || api.isEmpty()) {
|
||||||
|
FMCServer.log(Level.WARNING, "start report task fail because of not found report.api.info in configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File iconFile = new File(new File(plugin.getDataFolder().getParent()).getParent(), "server-icon.png");
|
||||||
|
Server server = plugin.getServer();
|
||||||
|
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
List<HTTP.PostFile> postFileList = new ArrayList<>();
|
||||||
|
|
||||||
|
params.put("id", config.getString("report.id").trim());
|
||||||
|
params.put("name", config.getString("report.name").trim());
|
||||||
|
params.put("core", server.getVersion().trim());
|
||||||
|
params.put("bootAt", System.currentTimeMillis());
|
||||||
|
params.put("clientURL", config.getString("report.clientURL").trim());
|
||||||
|
params.put("maxOnline", server.getMaxPlayers());
|
||||||
|
params.put("ip", config.getString("report.ip").trim());
|
||||||
|
if (iconFile.exists()) {
|
||||||
|
HTTP.PostFile file = new HTTP.PostFile();
|
||||||
|
file.setField("icon");
|
||||||
|
file.setFileName("server-icon.png");
|
||||||
|
file.setBytes(Files.readAllBytes(iconFile.toPath()));
|
||||||
|
postFileList.add(file);
|
||||||
|
}
|
||||||
|
String resp = HTTP.post(api, params, postFileList);
|
||||||
|
JsonObject respObj = JsonParser.parseString(resp).getAsJsonObject();
|
||||||
|
Integer code = respObj.get("code").getAsInt();
|
||||||
|
if (!code.equals(20000)) {
|
||||||
|
FMCServer.log(Level.WARNING, "report server info error: " + respObj.get("msg").getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 报告状态 */
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// 失败时延长周期,(15+-3) 秒
|
||||||
|
if (System.currentTimeMillis() - failAt < 1E3 * 15) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ServerStatusRequest.ServerStatus status = request.getStatus();
|
||||||
|
status.getOnlineList().clear();
|
||||||
|
Player[] players = server.getOnlinePlayers();
|
||||||
|
for (Player player : players) {
|
||||||
|
status.getOnlineList().add(player.getName());
|
||||||
|
}
|
||||||
|
status.setTps(tpsList);
|
||||||
|
status.setDebugging(FMCServer.getConfiguration().getBoolean("debug.enable"));
|
||||||
|
status.setReportAt(System.currentTimeMillis());
|
||||||
|
status.getJvm().setCpuUsed(operatingSystemMXBean.getProcessCpuLoad());
|
||||||
|
status.getJvm().getMemory().setUsed(jvmMemory.getHeapMemoryUsage().getUsed());
|
||||||
|
status.getJvm().getMemory().setCommitted(jvmMemory.getHeapMemoryUsage().getCommitted());
|
||||||
|
|
||||||
|
try {
|
||||||
|
String resp = HTTP.post(api, HTTP.ContentType.JSON, FMCServer.GSON.toJson(request));
|
||||||
|
if (resp == null || resp.isEmpty()) {
|
||||||
|
FMCServer.log(Level.WARNING, "report fail for empty result");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonObject respObj = JsonParser.parseString(resp).getAsJsonObject();
|
||||||
|
Integer code = respObj.get("code").getAsInt();
|
||||||
|
// 数据中心通知需要发送基本信息,与接口约定返回代码为 20001,消息为 REQUIRED_BASE_INFO
|
||||||
|
if (code.equals(20001) && respObj.get("msg").getAsString().equals("REQUIRED_BASE_INFO")) {
|
||||||
|
FMCServer.log(Level.WARNING, "server required send base info");
|
||||||
|
sendInfo();
|
||||||
|
} else if (!code.equals(20000)) {
|
||||||
|
failAt = System.currentTimeMillis();
|
||||||
|
FMCServer.log(Level.SEVERE, "report fail: " + respObj.get("msg").getAsString());
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
failAt = System.currentTimeMillis();
|
||||||
|
// 超时,连接失败的视为终端离线
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
252
src/main/java/cn/forevermc/server/mcpc/util/HTTP.java
Normal file
252
src/main/java/cn/forevermc/server/mcpc/util/HTTP.java
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
package cn.forevermc.server.mcpc.util;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP 操作
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-06 14:35
|
||||||
|
*/
|
||||||
|
public class HTTP {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求类型
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @version 2022-01-02 12:16
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ContentType {
|
||||||
|
|
||||||
|
/** 默认 URL 请求 */
|
||||||
|
DEFAULT(null),
|
||||||
|
|
||||||
|
/** FORM 表单模拟 */
|
||||||
|
FORM("application/x-www-form-urlencoded"),
|
||||||
|
|
||||||
|
/** JSON */
|
||||||
|
JSON("application/json; charset=utf-8"),
|
||||||
|
|
||||||
|
/** 数据流 */
|
||||||
|
STREAM("multipart/form-data; charset=utf-8; boundary=B7018kpqFPpgrWAKIR0lHNAanJEqJEyz");
|
||||||
|
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
ContentType(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送 POST 请求
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @param type 数据体类型
|
||||||
|
* @param data 数据
|
||||||
|
* @return 返回结果
|
||||||
|
* @throws Exception 请求异常
|
||||||
|
*/
|
||||||
|
public static String post(String url, ContentType type, String data) throws Exception {
|
||||||
|
HttpURLConnection connection = getConnection(url, type);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
if (data != null && !data.isEmpty()) {
|
||||||
|
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
|
||||||
|
bos.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
|
bos.flush();
|
||||||
|
bos.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = "";
|
||||||
|
if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
|
||||||
|
result = toString(connection.getInputStream());
|
||||||
|
}
|
||||||
|
connection.disconnect();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String post(String url, Map<String, Object> params, List<PostFile> postFileList) throws Exception {
|
||||||
|
final String newLine = "\r\n";
|
||||||
|
final String paramHeader = "Content-Disposition: form-data; name=\"%s\"";
|
||||||
|
final String fileHeader = "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"";
|
||||||
|
final String split = ContentType.STREAM.getValue().split("boundary=")[1];
|
||||||
|
|
||||||
|
HttpURLConnection connection = getConnection(url, ContentType.STREAM);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setChunkedStreamingMode(4096);
|
||||||
|
|
||||||
|
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
||||||
|
{
|
||||||
|
// 参数
|
||||||
|
for (Map.Entry<String, Object> param : params.entrySet()) {
|
||||||
|
dos.writeBytes("--" + split);
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
// 参数协议
|
||||||
|
dos.writeBytes(String.format(paramHeader, param.getKey()));
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes("Content-Type: text/plain; charset=UTF-8");
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes("Content-Transfer-Encoding: 8bit");
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
Object value = param.getValue();
|
||||||
|
if (value != null) {
|
||||||
|
dos.write(value.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
}
|
||||||
|
// 文件
|
||||||
|
for (PostFile postFile : postFileList) {
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(postFile.getBytes());
|
||||||
|
dos.writeBytes("--" + split);
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes(String.format(fileHeader, postFile.getField(), URLEncoder.encode(postFile.getFileName(), "UTF-8")));
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes("Content-Type: application/octet-stream");
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int l;
|
||||||
|
while ((l = bais.read(buffer)) != -1) {
|
||||||
|
dos.write(buffer, 0, l);
|
||||||
|
}
|
||||||
|
// 协议结尾
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes("--" + split + "--");
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
}
|
||||||
|
// 协议结尾
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.writeBytes("--" + split + "--");
|
||||||
|
dos.writeBytes(newLine);
|
||||||
|
dos.flush();
|
||||||
|
}
|
||||||
|
// 返回
|
||||||
|
if (connection.getResponseCode() >= 300) {
|
||||||
|
throw new Exception("HTTP Request error, Response code: " + connection.getResponseCode());
|
||||||
|
}
|
||||||
|
String result = toString(connection.getInputStream());
|
||||||
|
connection.disconnect();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接
|
||||||
|
*
|
||||||
|
* @param url URL 地址
|
||||||
|
* @param contentType Content-ContentType 数据类型
|
||||||
|
* @return HTTP 连接
|
||||||
|
*/
|
||||||
|
private static HttpURLConnection getConnection(String url, ContentType contentType) throws IOException, NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
|
||||||
|
// 转 URL 对象
|
||||||
|
url = url.startsWith("http") ? url : "http://" + url;
|
||||||
|
URL connectURL = new URI(url).toURL();
|
||||||
|
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) connectURL.openConnection();
|
||||||
|
// SSL 连接
|
||||||
|
if (url.trim().startsWith("https")) {
|
||||||
|
SSLContext sslcontext = SSLContext.getInstance("TLS");
|
||||||
|
sslcontext.init(null, new TrustManager[] {new X509TrustManager() {
|
||||||
|
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||||
|
}
|
||||||
|
}}, null);
|
||||||
|
if (connection instanceof HttpsURLConnection) {
|
||||||
|
((HttpsURLConnection) connection).setSSLSocketFactory(sslcontext.getSocketFactory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 数据类型
|
||||||
|
if (contentType != null && contentType.getValue() != null) {
|
||||||
|
connection.setRequestProperty("Content-Type", contentType.getValue());
|
||||||
|
}
|
||||||
|
connection.setRequestProperty("Token", FMCServer.getConfiguration().getString("report.token"));
|
||||||
|
// 超时
|
||||||
|
connection.setReadTimeout(3000);
|
||||||
|
connection.setConnectTimeout(3000);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取数据流为字符串
|
||||||
|
*
|
||||||
|
* @param is 输入流
|
||||||
|
* @return 字符串
|
||||||
|
* @throws IOException IO 异常
|
||||||
|
*/
|
||||||
|
private static String toString(InputStream is) throws IOException {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(is);
|
||||||
|
|
||||||
|
InputStreamReader isr = new InputStreamReader(bis, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
char[] buffer = new char[4096];
|
||||||
|
int l;
|
||||||
|
while ((l = isr.read(buffer)) != -1) {
|
||||||
|
sb.append(buffer, 0, l);
|
||||||
|
}
|
||||||
|
isr.close();
|
||||||
|
bis.close();
|
||||||
|
is.close();
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送文件
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-07 23:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class PostFile {
|
||||||
|
|
||||||
|
/** 字段名 */
|
||||||
|
private String field;
|
||||||
|
|
||||||
|
/** 文件名 */
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
/** 字节数据 */
|
||||||
|
private byte[] bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
75
src/main/java/cn/forevermc/server/mcpc/util/Util.java
Normal file
75
src/main/java/cn/forevermc/server/mcpc/util/Util.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package cn.forevermc.server.mcpc.util;
|
||||||
|
|
||||||
|
import cn.forevermc.server.mcpc.FMCServer;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工具
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-06 20:40
|
||||||
|
*/
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空安全的字符串转枚举
|
||||||
|
*
|
||||||
|
* @param enumType 枚举类
|
||||||
|
* @param name 枚举字段字符串
|
||||||
|
* @return 枚举
|
||||||
|
* @param <T> 枚举类型
|
||||||
|
*/
|
||||||
|
public static <T extends Enum<T>> T enumValueOf(Class<T> enumType, String name) {
|
||||||
|
if (name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T[] ts = enumType.getEnumConstants();
|
||||||
|
if (ts == null) {
|
||||||
|
throw new IllegalArgumentException(enumType.getName() + " is not an enum type");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < ts.length; i++) {
|
||||||
|
if (ts[i].name().equalsIgnoreCase(name)) {
|
||||||
|
return ts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出指令结果,如果是控制台则输出控制台,如果是玩家则输出到玩家
|
||||||
|
*
|
||||||
|
* @param sender 发送者
|
||||||
|
* @param level 等级
|
||||||
|
* @param msg 消息
|
||||||
|
*/
|
||||||
|
public static void returnMsg(CommandSender sender, Level level, String msg) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
ChatColor color = level == Level.WARNING ? ChatColor.GREEN : ChatColor.RED;
|
||||||
|
player.sendMessage(color + msg);
|
||||||
|
} else {
|
||||||
|
FMCServer.log(level, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机字符串
|
||||||
|
*
|
||||||
|
* @param length 长度
|
||||||
|
* @return 随机字符串
|
||||||
|
*/
|
||||||
|
public static String randomString(int length) {
|
||||||
|
String pool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
SecureRandom r = new SecureRandom();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
sb.append(pool.charAt(r.nextInt(pool.length() - 1)));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/resources/plugin.yml
Normal file
17
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
name: FMCServer
|
||||||
|
main: cn.forevermc.server.mcpc.FMCServer
|
||||||
|
version: '0.0.1'
|
||||||
|
|
||||||
|
author: Timi
|
||||||
|
website: imyeyu.net
|
||||||
|
description: This plugin is ForeverMC Server status reporter
|
||||||
|
|
||||||
|
commands:
|
||||||
|
debug:
|
||||||
|
description: 启用或禁用维护模式
|
||||||
|
usage: "/<command> [true|false|status]"
|
||||||
|
permission: op
|
||||||
|
staff:
|
||||||
|
description: 添加或移除维护人员
|
||||||
|
usage: "/<command> [add|remove|list] <value>"
|
||||||
|
permission: op
|
||||||
Reference in New Issue
Block a user