Initial Code
All checks were successful
Build Plugin / build-test (push) Successful in 48s

This commit is contained in:
tobid7 2024-11-23 18:17:14 +01:00
commit c747835eea
8 changed files with 284 additions and 0 deletions

View File

@ -0,0 +1,67 @@
name: Build Plugin
run-name: Build Plugin with maven
on:
push:
branches:
- '*'
tags:
- 'v*'
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Tools
run: apt update -y && apt install -y maven
- name: Build
run: mvn clean package
- name: Upload
uses: actions/upload-artifact@v3
with:
name: d7serverlite
path: target/d7serverlite*.jar
- name: Create Pre Release
run: |
FILES=./target/d7serverlite*.jar
USER=D7MC
REPO=D7ServerLite
# Set up variables
AUTH_HEADER="Authorization: token ${{ secrets.TOKEN }}"
CONTENT_TYPE="Content-Type: application/json"
API_URL="https://dev.npid7.de/api/v1/repos/$USER/$REPO/releases"
COMMIT_HASH=$(git rev-parse --short HEAD)
AUTHOR_NAME=$(git log -1 --pretty=format:'%an')
COMMIT_SUBJECT=$(git log -1 --pretty=format:'%s')
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%b')
DATETIME=$(date +'%Y%m%d_%H%M')
echo "Create Release"
RELEASE_INFO="{\"tag_name\": \"p$DATETIME\", \"name\": \"Test | $COMMIT_HASH\", \"body\": \"$AUTHOR_NAME - $COMMIT_SUBJECT\\n\\n$COMMIT_MESSAGE\", \"prerelease\": true}"
RESPONSE=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d "$RELEASE_INFO" "$API_URL")
RELEASE_ID=$(echo $RESPONSE | jq --raw-output '.id')
echo "Release created with ID: $RELEASE_ID"
if [ "$RELEASE_ID" == "null" ]; then
echo "Failed to create release."
exit 1
fi
echo "Upload File/s"
for file in $FILES; do
if [ -f "$file" ]; then
FILE_NAME=$(basename "$file")
FILE_PATH="$file"
FILE_SIZE=$(stat -c%s "$FILE_PATH")
UPLOAD_URL="https://dev.npid7.de/api/v1/repos/$USER/$REPO/releases/$RELEASE_ID/assets?name=$FILE_NAME"
CONTENT_LENGTH="Content-Length: $FILE_SIZE"
CONTENT_TYPE="Content-Type: application/7z-x-compressed"
echo "Uploading asset: $FILE_NAME"
RESPONSE=$(curl -s -X POST -H "Authorization: token ${{ secrets.TOKEN }}" \
-H "$CONTENT_LENGTH" -H "$CONTENT_TYPE" \
--upload-file "$FILE_PATH" "$UPLOAD_URL")
if echo "$RESPONSE" | jq -e '.message' >/dev/null; then
echo "Error uploading $FILE_NAME: $(echo "$RESPONSE" | jq -r .message)"
exit 1
fi
echo "Successfully uploaded $FILE_NAME"
fi
done

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
install.bat

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

76
pom.xml Normal file
View File

@ -0,0 +1,76 @@
<?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>de.npid7.serverlite</groupId>
<artifactId>d7serverlite</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,35 @@
package de.npid7.serverlite;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import de.npid7.serverlite.Helpers.Spielzeit;
import de.npid7.serverlite.Tasks.TablistTask;
/*
* d7serverlite java plugin
*/
public class D7ServerLite extends JavaPlugin {
private static D7ServerLite inst;
private TablistTask tablistUpdater;
@Override
public void onLoad() {
inst = this;
}
@Override
public void onEnable() {
tablistUpdater = new TablistTask();
}
@Override
public void onDisable() {}
public static D7ServerLite getInst() {
return inst;
}
}

View File

@ -0,0 +1,27 @@
package de.npid7.serverlite.Helpers;
public class Spielzeit {
public static String formatTicks(int ticks) {
int time = ticks / 20;
String timers = new String("");
int day = time / 86400;
int hours = (time % 86400) / 3600;
int minutes = (time % 3600) / 60;
int seconds = time % 60;
if (time > -1 && time < 60) {
timers = String.format("%02ds", seconds);
} else if (time > 59 && time < 3600) {
timers = String.format("%02dm %02ds", minutes, seconds);
} else if (time > 3599 && time < 86400) {
timers = String.format("%02dh %02dm %02ds", hours, minutes, seconds);
} else if (time > 86399) {
timers = String.format("%02dd %02dh %02dm %02ds", day, hours, minutes, seconds);
}
return timers;
}
public static int getHours(int ticks) {
int time = ticks / 20;
return time / 3600;
}
}

View File

@ -0,0 +1,70 @@
package de.npid7.serverlite.Tasks;
import de.npid7.serverlite.D7ServerLite;
import de.npid7.serverlite.Helpers.Spielzeit;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class TablistTask {
long lastTickNano = System.nanoTime();
long lastSecondNano = lastTickNano;
int ticksThisSec = 0;
double tps = 20.0;
double mspt = 0.0;
double total_mspt = 0.0;
long msptlt;
private void CalcTPS() {
long now = System.nanoTime();
double now_mspt = (now - lastTickNano) / 1000000.0;
lastTickNano = now;
total_mspt += now_mspt;
if (now - lastSecondNano >= 1000000000.0) {
tps = ticksThisSec;
// Fake Value
if (tps == 21)
tps = 20;
mspt = total_mspt / ticksThisSec;
total_mspt = 0;
ticksThisSec = 0;
lastSecondNano = now;
}
ticksThisSec++;
}
public TablistTask() {
run();
}
private void displayTablist() {
for (Player pl : Bukkit.getServer().getOnlinePlayers()) {
int playtime = Spielzeit.getHours(pl.getStatistic(Statistic.TOTAL_WORLD_TIME));
String str = " Stunden";
if (playtime == 1) {
str = " Stunde";
}
pl.setPlayerListHeader(
"\n§x§5§5§5§5§5§5§lѕ§x§5§B§5§B§5§B§l§x§6§1§6§1§6§1§lʀ§x§6§7§6§7§6§7§l§x§6§D§6§D§6§D§lɪ§x§7§3§7§3§7§3§l§x§7§9§7§9§7§9§lᴀ§x§8§0§8§0§8§0§lʟ§x§8§6§8§6§8§6§lᴘ§x§8§C§8§C§8§C§lʀ§x§9§2§9§2§9§2§l§x§9§8§9§8§9§8§lᴊ§x§9§E§9§E§9§E§lᴇ§x§A§4§A§4§A§4§lᴋ§x§A§A§A§A§A§A§lᴛ\n"
+ "\n" + ChatColor.GRAY.toString() + "ᴅᴇɪɴ ᴘɪɴɢ" + ChatColor.DARK_GRAY.toString() + ": "
+ ChatColor.GREEN.toString() + pl.getPing() + " " + ChatColor.GRAY.toString()
+ "ѕᴇʀᴠᴇʀ ᴛᴘѕ" + ChatColor.DARK_GRAY.toString() + ": " + ChatColor.GREEN.toString()
+ String.format("%.1f", tps) + "\n\n" + ChatColor.GRAY.toString() + "ѕᴘɪᴇʟᴢᴇɪᴛ"
+ ChatColor.DARK_GRAY.toString() + ": " + ChatColor.GREEN.toString() + playtime + str
+ "\n");
pl.setPlayerListFooter("\n");
}
}
private void run() {
new BukkitRunnable() {
@Override
public void run() {
CalcTPS();
displayTablist();
}
}.runTaskTimer(D7ServerLite.getInst(), 0, 0);
}
}

View File

@ -0,0 +1,4 @@
name: D7SerevrLite
main: de.npid7.serverlite.D7ServerLite
version: 1.0
api-version: 1.17