commit 420b5d26855e97175579b196460604e64b401f88 Author: tobid7 Date: Fri Nov 22 18:38:23 2024 +0100 Initial Code diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..0efa8d7 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ddd030 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +install.bat \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..82db772 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.search.scope": "all" +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..531f04a --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dad09c6 --- /dev/null +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..455d177 --- /dev/null +++ b/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + de.npid7.mc + starterkit + 1.0 + + + UTF-8 + 1.7 + 1.7 + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + junit + junit + 4.11 + test + + + + org.spigotmc + spigot-api + 1.17.1-R0.1-SNAPSHOT + provided + + + + + + + + maven-clean-plugin + 3.1.0 + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/src/main/java/de/npid7/mc/Configs/PluginConfig.java b/src/main/java/de/npid7/mc/Configs/PluginConfig.java new file mode 100644 index 0000000..83a1781 --- /dev/null +++ b/src/main/java/de/npid7/mc/Configs/PluginConfig.java @@ -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 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 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 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; + } +} diff --git a/src/main/java/de/npid7/mc/Listeners/PlayerJoinListener.java b/src/main/java/de/npid7/mc/Listeners/PlayerJoinListener.java new file mode 100644 index 0000000..dafecf5 --- /dev/null +++ b/src/main/java/de/npid7/mc/Listeners/PlayerJoinListener.java @@ -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)); + } + } +} diff --git a/src/main/java/de/npid7/mc/Starterkit.java b/src/main/java/de/npid7/mc/Starterkit.java new file mode 100644 index 0000000..ed2dd1c --- /dev/null +++ b/src/main/java/de/npid7/mc/Starterkit.java @@ -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; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..c934229 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,4 @@ +name: Starterkit +main: de.npid7.mc.Starterkit +version: 1.0 +api-version: 1.17 \ No newline at end of file