This commit is contained in:
commit
420b5d2685
67
.gitea/workflows/build.yaml
Normal file
67
.gitea/workflows/build.yaml
Normal 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: starterkit
|
||||
path: target/starterkit*.jar
|
||||
- name: Create Pre Release
|
||||
run: |
|
||||
FILES=./target/starterkit*.jar
|
||||
USER=tobid7
|
||||
REPO=Starterkit
|
||||
# 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
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target/
|
||||
install.bat
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "interactive",
|
||||
"java.search.scope": "all"
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
8
README.md
Normal file
8
README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Starterkit
|
||||
Minecraft Plugin to give Players a set of Items/Food at their first Join
|
||||
|
||||
Version 1.17.1+
|
||||
# Building
|
||||
```bash
|
||||
mvn clean package
|
||||
```
|
76
pom.xml
Normal file
76
pom.xml
Normal 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.mc</groupId>
|
||||
<artifactId>starterkit</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>
|
81
src/main/java/de/npid7/mc/Configs/PluginConfig.java
Normal file
81
src/main/java/de/npid7/mc/Configs/PluginConfig.java
Normal file
@ -0,0 +1,81 @@
|
||||
package de.npid7.mc.Configs;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PluginConfig {
|
||||
File file = null;
|
||||
|
||||
int cfg_version = 0;
|
||||
HashMap<UUID, String> players_joined = new HashMap<>();
|
||||
public PluginConfig(String path) {
|
||||
file = new File(path);
|
||||
Load();
|
||||
}
|
||||
|
||||
public boolean Load() {
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
FileReader r = new FileReader(file);
|
||||
JsonParser prs = new JsonParser();
|
||||
JsonObject js = prs.parse(r).getAsJsonObject();
|
||||
r.close();
|
||||
int pver = js.get("version").getAsInt();
|
||||
if (pver != cfg_version) {
|
||||
file.delete();
|
||||
return false;
|
||||
}
|
||||
for (Map.Entry<String, JsonElement> e :
|
||||
js.get("players_joined").getAsJsonObject().entrySet()) {
|
||||
players_joined.put(UUID.fromString(e.getKey()), e.getValue().getAsString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean Check(UUID id, String name) {
|
||||
if (players_joined.containsKey(id)) {
|
||||
return true;
|
||||
}
|
||||
players_joined.put(id, name);
|
||||
Save();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean Save() {
|
||||
JsonObject js = new JsonObject();
|
||||
js.addProperty("version", cfg_version);
|
||||
JsonObject pjm = new JsonObject();
|
||||
for (Map.Entry<UUID, String> e : players_joined.entrySet()) {
|
||||
pjm.addProperty(e.getKey().toString(), e.getValue());
|
||||
}
|
||||
js.add("players_joined", pjm);
|
||||
try {
|
||||
FileWriter w = new FileWriter(file);
|
||||
Gson g = new GsonBuilder().setPrettyPrinting().create();
|
||||
g.toJson(js, w);
|
||||
w.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
19
src/main/java/de/npid7/mc/Listeners/PlayerJoinListener.java
Normal file
19
src/main/java/de/npid7/mc/Listeners/PlayerJoinListener.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.npid7.mc.Listeners;
|
||||
|
||||
import de.npid7.mc.Starterkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player pl = e.getPlayer();
|
||||
if (!Starterkit.getInstance().getPluginConfig().Check(pl.getUniqueId(), pl.getName())) {
|
||||
pl.getInventory().addItem(new ItemStack(Material.BREAD, 32));
|
||||
}
|
||||
}
|
||||
}
|
36
src/main/java/de/npid7/mc/Starterkit.java
Normal file
36
src/main/java/de/npid7/mc/Starterkit.java
Normal file
@ -0,0 +1,36 @@
|
||||
package de.npid7.mc;
|
||||
|
||||
import de.npid7.mc.Configs.PluginConfig;
|
||||
import de.npid7.mc.Listeners.PlayerJoinListener;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Starterkit extends JavaPlugin {
|
||||
private static Starterkit instance;
|
||||
private PluginConfig cfg;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Set Static reference
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdirs();
|
||||
}
|
||||
|
||||
cfg = new PluginConfig(getDataFolder() + "/config.json");
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this);
|
||||
}
|
||||
|
||||
public static Starterkit getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public PluginConfig getPluginConfig() {
|
||||
return cfg;
|
||||
}
|
||||
}
|
4
src/main/resources/plugin.yml
Normal file
4
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
||||
name: Starterkit
|
||||
main: de.npid7.mc.Starterkit
|
||||
version: 1.0
|
||||
api-version: 1.17
|
Loading…
Reference in New Issue
Block a user