From d5ec5554dd5e297acc7d19884e943be7d655afb4 Mon Sep 17 00:00:00 2001 From: Patrick <147879351+WinniePatGG@users.noreply.github.com> Date: Fri, 1 May 2026 19:44:14 +0200 Subject: [PATCH] first commit --- .gitignore | 5 + LICENSE | 21 ++ README.md | 30 +++ build.gradle | 63 +++++ gradle.properties | 0 gradlew | 249 ++++++++++++++++++ gradlew.bat | 92 +++++++ settings.gradle | 1 + .../de/winniepat/lobbyPlugin/LobbyPlugin.java | 57 ++++ .../lobbyPlugin/commands/CodingCommand.java | 134 ++++++++++ .../lobbyPlugin/commands/DiscordCommand.java | 26 ++ .../lobbyPlugin/commands/ManageCommand.java | 38 +++ .../lobbyPlugin/commands/PetCommand.java | 26 ++ .../lobbyPlugin/commands/SpawnCommand.java | 15 ++ .../lobbyPlugin/commands/TrailCommand.java | 27 ++ .../listeners/CodingCleanupListener.java | 35 +++ .../listeners/HungerPreventListener.java | 12 + .../listeners/ManageInventoryListener.java | 56 ++++ .../listeners/RespawnListener.java | 18 ++ .../listeners/ServerJoinListener.java | 18 ++ .../listeners/VoidFallListener.java | 32 +++ .../lobbyPlugin/menus/ManageMenu.java | 51 ++++ .../lobbyPlugin/pets/FollowPlayerTask.java | 34 +++ .../lobbyPlugin/pets/PetActionRegistry.java | 19 ++ .../lobbyPlugin/pets/PetManager.java | 129 +++++++++ .../lobbyPlugin/pets/PetSelectorGUI.java | 57 ++++ .../winniepat/lobbyPlugin/pets/PetType.java | 44 ++++ .../lobbyPlugin/trails/TrailGUI.java | 76 ++++++ .../lobbyPlugin/trails/TrailManager.java | 60 +++++ .../lobbyPlugin/trails/TrailType.java | 35 +++ src/main/resources/plugin.yml | 21 ++ 31 files changed, 1481 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/de/winniepat/lobbyPlugin/LobbyPlugin.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/CodingCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/DiscordCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/ManageCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/PetCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/SpawnCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/commands/TrailCommand.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/CodingCleanupListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/HungerPreventListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/ManageInventoryListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/RespawnListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/ServerJoinListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/listeners/VoidFallListener.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/menus/ManageMenu.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/pets/FollowPlayerTask.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/pets/PetActionRegistry.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/pets/PetManager.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/pets/PetSelectorGUI.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/pets/PetType.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/trails/TrailGUI.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/trails/TrailManager.java create mode 100644 src/main/java/de/winniepat/lobbyPlugin/trails/TrailType.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8cb336 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/build +/.idea +/.gradle +gradle +server diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..958ab94 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 WinniePatGG + +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..637ec00 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# 🌙 LunarisMC Lobby Plugin + +[LunarisMC.de](https://www.lunaris-mc.de/) +This plugin handles essential lobby functions for our Minecraft Network Lobby, ensuring a smooth and user-friendly experience for all players upon joining. +Hardcoded variables are the reason for not creating a release. If you want to use, change values in code and build yourself + +--- + +## 📦 Features + +✅ Clear player inventory on join +✅ Teleport player on join +✅ Set spawn location and teleport on void fall + +--- + +## 🛠️ Installation + +1. build it yourself (see below) + +--- + +## 💻 Building + +This plugin uses **Gradle** for building. + +```bash +git clone https://github.com/WinniePatGG/LobbyPlugin.git +cd LobbyPlugin +gradlew build diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..dc830a6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,63 @@ +plugins { + id 'java' + id("xyz.jpenilla.run-paper") version "2.3.1" +} + +group = 'de.winniepat' +version = '1.0' + +repositories { + mavenCentral() + maven { + name = "papermc-repo" + url = "https://repo.papermc.io/repository/maven-public/" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/groups/public/" + } +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") +} + +tasks { + runServer { + minecraftVersion("1.21") + } +} + +def targetJavaVersion = 21 +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + options.release.set(targetJavaVersion) + } +} + +processResources { + def props = [version: version] + inputs.properties props + filteringCharset 'UTF-8' + filesMatching('plugin.yml') { + expand props + } +} + +build.doLast { + copy { + from("$buildDir/libs/LobbyPlugin-1.0.jar") + into("C:/Users/winnie/Documents/lunaris/LobbyPlugin/server/plugins") + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..b740cf1 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..8b3f367 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'LobbyPlugin' diff --git a/src/main/java/de/winniepat/lobbyPlugin/LobbyPlugin.java b/src/main/java/de/winniepat/lobbyPlugin/LobbyPlugin.java new file mode 100644 index 0000000..53c90de --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/LobbyPlugin.java @@ -0,0 +1,57 @@ +package de.winniepat.lobbyPlugin; + +import de.winniepat.lobbyPlugin.commands.*; +import de.winniepat.lobbyPlugin.listeners.*; +import de.winniepat.lobbyPlugin.pets.PetManager; +import de.winniepat.lobbyPlugin.trails.*; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Objects; + +public final class LobbyPlugin extends JavaPlugin { + + private PetManager petManager; + private TrailManager trailManager; + private TrailGUI trailGUI; + CodingCommand codingCommand = new CodingCommand(this, this); + + @Override + public void onEnable() { + petManager = new PetManager(this); + + trailManager = new TrailManager(this); + trailGUI = new TrailGUI(trailManager); + + registerCommands(); + registerListeners(); + + trailManager.startTrailTask(); + + getLogger().info("Started successfully"); + } + + @Override + public void onDisable() { + petManager.removeAllPets(); + getLogger().info("Shut down successfully"); + } + + private void registerCommands() { + Objects.requireNonNull(getCommand("spawn")).setExecutor(new SpawnCommand()); + Objects.requireNonNull(getCommand("manage")).setExecutor(new ManageCommand()); + Objects.requireNonNull(getCommand("discord")).setExecutor(new DiscordCommand()); + Objects.requireNonNull(getCommand("pet")).setExecutor(new PetCommand(petManager)); + Objects.requireNonNull(getCommand("trail")).setExecutor(new TrailCommand(trailGUI)); + Objects.requireNonNull(getCommand("coding")).setExecutor(new CodingCommand(this, this)); + } + + private void registerListeners() { + getServer().getPluginManager().registerEvents(new CodingCleanupListener(codingCommand), this); + getServer().getPluginManager().registerEvents(new ManageInventoryListener(), this); + getServer().getPluginManager().registerEvents(new RespawnListener(), this); + getServer().getPluginManager().registerEvents(new ServerJoinListener(), this); + getServer().getPluginManager().registerEvents(trailGUI, this); + getServer().getPluginManager().registerEvents(new VoidFallListener(this), this); + getServer().getPluginManager().registerEvents(new HungerPreventListener(),this); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/CodingCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/CodingCommand.java new file mode 100644 index 0000000..8b20cfa --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/CodingCommand.java @@ -0,0 +1,134 @@ +package de.winniepat.lobbyPlugin.commands; + +import de.winniepat.lobbyPlugin.LobbyPlugin; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class CodingCommand implements CommandExecutor { + + private Plugin plugin; + private LobbyPlugin lobbyPlugin; + private final Map codingStands = new HashMap<>(); + private final Map animationTasks = new HashMap<>(); + + private static final String[] COLORS = { + "#FF0000", "#FF4000", "#FF8000", "#FFBF00", "#FFFF00", + "#BFFF00", "#80FF00", "#40FF00", "#00FF00", "#00FF40", + "#00FF80", "#00FFBF", "#00FFFF", "#00BFFF", "#0080FF", + "#0040FF", "#0000FF", "#4000FF", "#8000FF", "#BF00FF", + "#FF00FF" + }; + + private final String[] frames = new String[21]; + + public CodingCommand(Plugin plugin, LobbyPlugin lobbyPlugin) { + this.plugin = plugin; + this.lobbyPlugin = lobbyPlugin; + + char[] glyphs = { + '\uE014', '\uE015', '\uE016', '\uE017', '\uE018', + '\uE019', '\uE020', '\uE021', '\uE022', '\uE023', + '\uE024', '\uE025', '\uE026', '\uE035', '\uE028', + '\uE029', '\uE030', '\uE031', '\uE032', '\uE033', + '\uE034' + }; + for (int i = 0; i < 21; i++) { + frames[i] = glyphs[i] + " " + rgb("Coding...", COLORS[i]); + } + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player player)) return false; + + if (args.length != 1 || (!args[0].equalsIgnoreCase("on") && !args[0].equalsIgnoreCase("off"))) { + sender.sendMessage("§cUse /coding on or /coding off"); + return true; + } + + UUID uuid = player.getUniqueId(); + + if (args[0].equalsIgnoreCase("on")) { + if (codingStands.containsKey(uuid)) { + sender.sendMessage("§eYou're already marked as coding."); + return true; + } + + Location loc = player.getLocation().add(0, 2.2, 0); + ArmorStand stand = player.getWorld().spawn(loc, ArmorStand.class); + stand.setVisible(false); + stand.setCustomNameVisible(true); + stand.setGravity(false); + stand.setMarker(true); + + codingStands.put(uuid, stand); + + BukkitRunnable task = new BukkitRunnable() { + int tick = 0; + + @Override + public void run() { + if (!stand.isValid() || !player.isOnline()) { + this.cancel(); + if (stand.isValid()) stand.remove(); + codingStands.remove(uuid); + animationTasks.remove(uuid); + return; + } + + stand.teleport(player.getLocation().add(0, 2.2, 0)); + stand.setCustomName(frames[tick % frames.length]); + tick++; + } + }; + task.runTaskTimer(plugin, 0L, 4L); + + animationTasks.put(uuid, task); + sender.sendMessage("§aYou are now marked as coding."); + } + + if (args[0].equalsIgnoreCase("off")) { + if (animationTasks.containsKey(uuid)) { + animationTasks.get(uuid).cancel(); + animationTasks.remove(uuid); + } + + if (codingStands.containsKey(uuid)) { + ArmorStand stand = codingStands.remove(uuid); + if (stand != null && !stand.isDead()) { + stand.remove(); + } + player.sendMessage("§aYou are no longer marked as coding."); + } else { + sender.sendMessage("§cError while executing."); + } + } + return true; + } + + private static String rgb(String text, String hexColor) { + StringBuilder out = new StringBuilder("§x"); + for (char c : hexColor.substring(1).toCharArray()) { + out.append('§').append(c); + } + return out + text; + } + + public Map getCodingStands() { + return codingStands; + } + + public Map getAnimationTasks() { + return animationTasks; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/DiscordCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/DiscordCommand.java new file mode 100644 index 0000000..ecac7e6 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/DiscordCommand.java @@ -0,0 +1,26 @@ +package de.winniepat.lobbyPlugin.commands; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class DiscordCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(sender instanceof Player) { + Player player = (Player) sender; + + TextComponent message = new TextComponent("Click here to join our discord server"); + message.setColor(ChatColor.AQUA); + message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://dc.lunaris-mc.de")); + + player.sendMessage(message); + } + return true; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/ManageCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/ManageCommand.java new file mode 100644 index 0000000..8047cd0 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/ManageCommand.java @@ -0,0 +1,38 @@ +package de.winniepat.lobbyPlugin.commands; + +import de.winniepat.lobbyPlugin.menus.ManageMenu; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ManageCommand implements CommandExecutor { + + @Override + public boolean onCommand( CommandSender sender, Command command, String s, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can execute this command!"); + return true; + } + + Player player = (Player) sender; + + if(args.length != 1) { + player.sendMessage(ChatColor.RED + "Use: /manage "); + return true; + } + + Player target = Bukkit.getPlayer(args[0]); + + if(target == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } + + new ManageMenu(player, target); + + return true; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/PetCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/PetCommand.java new file mode 100644 index 0000000..546aa48 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/PetCommand.java @@ -0,0 +1,26 @@ +package de.winniepat.lobbyPlugin.commands; + +import de.winniepat.lobbyPlugin.pets.PetManager; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class PetCommand implements CommandExecutor { + private final PetManager petManager; + + public PetCommand(PetManager petManager) { + this.petManager = petManager; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player player)) { + sender.sendMessage("Only players can use this command."); + return true; + } + + petManager.openPetSelectionGUI(player); + return true; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/SpawnCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/SpawnCommand.java new file mode 100644 index 0000000..a399a70 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/SpawnCommand.java @@ -0,0 +1,15 @@ +package de.winniepat.lobbyPlugin.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class SpawnCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tp " + sender.getName() + " 38.5 39 83.5 90 0"); + return false; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/commands/TrailCommand.java b/src/main/java/de/winniepat/lobbyPlugin/commands/TrailCommand.java new file mode 100644 index 0000000..252c5cb --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/commands/TrailCommand.java @@ -0,0 +1,27 @@ +package de.winniepat.lobbyPlugin.commands; + +import de.winniepat.lobbyPlugin.trails.TrailGUI; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TrailCommand implements CommandExecutor { + + private final TrailGUI trailGUI; + + public TrailCommand(TrailGUI trailGUI) { + this.trailGUI = trailGUI; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player player)) { + sender.sendMessage("Only players can use this command."); + return true; + } + + trailGUI.open(player); + return true; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/CodingCleanupListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/CodingCleanupListener.java new file mode 100644 index 0000000..965271e --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/CodingCleanupListener.java @@ -0,0 +1,35 @@ +package de.winniepat.lobbyPlugin.listeners; + +import de.winniepat.lobbyPlugin.commands.CodingCommand; +import org.bukkit.entity.ArmorStand; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.UUID; + +public class CodingCleanupListener implements Listener { + + private final CodingCommand codingCommand; + + public CodingCleanupListener(CodingCommand codingCommand) { + this.codingCommand = codingCommand; + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + UUID uuid = event.getPlayer().getUniqueId(); + + if (codingCommand.getAnimationTasks().containsKey(uuid)) { + codingCommand.getAnimationTasks().get(uuid).cancel(); + codingCommand.getAnimationTasks().remove(uuid); + } + + if (codingCommand.getCodingStands().containsKey(uuid)) { + ArmorStand stand = codingCommand.getCodingStands().remove(uuid); + if (stand != null && !stand.isDead()) { + stand.remove(); + } + } + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/HungerPreventListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/HungerPreventListener.java new file mode 100644 index 0000000..9978a32 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/HungerPreventListener.java @@ -0,0 +1,12 @@ +package de.winniepat.lobbyPlugin.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.FoodLevelChangeEvent; + +public class HungerPreventListener implements Listener { + @EventHandler + public void onHungerChange(FoodLevelChangeEvent event) { + event.setCancelled(true); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/ManageInventoryListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/ManageInventoryListener.java new file mode 100644 index 0000000..7aaa5dc --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/ManageInventoryListener.java @@ -0,0 +1,56 @@ +package de.winniepat.lobbyPlugin.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +import java.time.Instant; + +public class ManageInventoryListener implements Listener { + + public ManageInventoryListener() { + + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (!event.getView().getTitle().equals(ChatColor.RED + "Manage Player")){ + return; + } + + event.setCancelled(true); + + if(event.getCurrentItem() == null){ + return; + } + + Player player = (Player) event.getWhoClicked(); + Player target = Bukkit.getPlayer(event.getView().getItem(4).getItemMeta().getDisplayName()); + + if(target == null) { + player.closeInventory(); + player.sendMessage(ChatColor.RED + "Target is not online anymore"); + return; + } + + if(event.getCurrentItem().getType() == Material.RED_DYE){ + target.setHealth(20); + player.sendMessage(ChatColor.GREEN + target.getName() + " was healed"); + }else if(event.getCurrentItem().getType() == Material.IRON_SWORD){ + target.setHealth(0); + player.sendMessage(ChatColor.GREEN + target.getName() + " was killed"); + }else if(event.getCurrentItem().getType() == Material.GRAY_DYE){ + target.kick(); + player.sendMessage(ChatColor.GREEN + target.getName() + " was kicked"); + }else if(event.getCurrentItem().getType() == Material.MACE) { + target.banPlayer("Join the Discord for more information "); + player.sendMessage(ChatColor.GREEN + target.getName() + " was banned"); + } + player.closeInventory(); + + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/RespawnListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/RespawnListener.java new file mode 100644 index 0000000..ec00811 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/RespawnListener.java @@ -0,0 +1,18 @@ +package de.winniepat.lobbyPlugin.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerRespawnEvent; + +public class RespawnListener implements Listener { + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event){ + Player player = event.getPlayer(); + Location spawnLoc = new Location(Bukkit.getWorld("world"), 38.5, 39, 83.5, 90, 0); + player.teleport(spawnLoc); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/ServerJoinListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/ServerJoinListener.java new file mode 100644 index 0000000..91eeabb --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/ServerJoinListener.java @@ -0,0 +1,18 @@ +package de.winniepat.lobbyPlugin.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class ServerJoinListener implements Listener { + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event){ + Player player = event.getPlayer(); + Location spawnLoc = new Location(Bukkit.getWorld("world"), 38.5, 39, 83.5, 90, 0); + player.teleport(spawnLoc); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/listeners/VoidFallListener.java b/src/main/java/de/winniepat/lobbyPlugin/listeners/VoidFallListener.java new file mode 100644 index 0000000..6f08824 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/listeners/VoidFallListener.java @@ -0,0 +1,32 @@ +package de.winniepat.lobbyPlugin.listeners; + +import de.winniepat.lobbyPlugin.LobbyPlugin; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class VoidFallListener implements Listener { + + private final LobbyPlugin plugin; + + public VoidFallListener(LobbyPlugin plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPlayerFall(PlayerMoveEvent event) { + Player player = event.getPlayer(); + Location loc = player.getLocation(); + + if (loc.getY() <= -70) { + World world = player.getWorld(); + Location spawnLocation = new Location(world, 38.5, 39, 83.5, 90.0f, 0.0f); + player.teleport(spawnLocation); + player.sendMessage(ChatColor.RED + "You fell off the map!"); + } + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/menus/ManageMenu.java b/src/main/java/de/winniepat/lobbyPlugin/menus/ManageMenu.java new file mode 100644 index 0000000..b399aa7 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/menus/ManageMenu.java @@ -0,0 +1,51 @@ +package de.winniepat.lobbyPlugin.menus; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Arrays; + +public class ManageMenu { + + public ManageMenu(Player player, Player target) { + + Inventory inventory = Bukkit.createInventory(null, 27, ChatColor.RED + "Manage Player"); + + ItemStack targetHead = new ItemStack(Material.PLAYER_HEAD, 1); + ItemMeta targetHeadMeta = targetHead.getItemMeta(); + targetHeadMeta.setDisplayName(target.getName()); + targetHead.setItemMeta(targetHeadMeta); + inventory.setItem(4, targetHead); + + ItemStack heal = new ItemStack(Material.RED_DYE, 1); + ItemMeta healMeta = heal.getItemMeta(); + healMeta.setDisplayName(ChatColor.RED + "Heal"); + heal.setItemMeta(healMeta); + inventory.setItem(9, heal); + + ItemStack kill = new ItemStack(Material.IRON_SWORD, 1); + ItemMeta killMeta = kill.getItemMeta(); + killMeta.setDisplayName(ChatColor.BLUE + "Kill"); + kill.setItemMeta(killMeta); + inventory.setItem(11, kill); + + ItemStack kick = new ItemStack(Material.GRAY_DYE, 1); + ItemMeta kickMeta = kick.getItemMeta(); + kickMeta.setDisplayName(ChatColor.GRAY + "Kick"); + kick.setItemMeta(kickMeta); + inventory.setItem(13, kick); + + ItemStack ban = new ItemStack(Material.MACE, 1); + ItemMeta banMeta = ban.getItemMeta(); + banMeta.setDisplayName(ChatColor.DARK_RED + "Ban"); + ban.setItemMeta(banMeta); + inventory.setItem(15, ban); + + player.openInventory(inventory); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/pets/FollowPlayerTask.java b/src/main/java/de/winniepat/lobbyPlugin/pets/FollowPlayerTask.java new file mode 100644 index 0000000..da84e03 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/pets/FollowPlayerTask.java @@ -0,0 +1,34 @@ +package de.winniepat.lobbyPlugin.pets; + +import org.bukkit.entity.Mob; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + +public class FollowPlayerTask extends BukkitRunnable { + private final Plugin plugin; + private final Mob pet; + private final Player owner; + + public FollowPlayerTask(Plugin plugin, Mob pet, Player owner) { + this.plugin = plugin; + this.pet = pet; + this.owner = owner; + } + + public void start() { + this.runTaskTimer(plugin, 0L, 20L); + } + + @Override + public void run() { + if (!owner.isOnline() || pet.isDead()) { + cancel(); + return; + } + + if (pet.getLocation().distance(owner.getLocation()) > 3) { + pet.getPathfinder().moveTo(owner.getLocation()); + } + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/pets/PetActionRegistry.java b/src/main/java/de/winniepat/lobbyPlugin/pets/PetActionRegistry.java new file mode 100644 index 0000000..c5cd54b --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/pets/PetActionRegistry.java @@ -0,0 +1,19 @@ +package de.winniepat.lobbyPlugin.pets; + +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +public class PetActionRegistry { + private static final Map> actions = new HashMap<>(); + + public static void register(String key, Consumer action) { + actions.put(key, action); + } + + public static Consumer get(String key) { + return actions.get(key); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/pets/PetManager.java b/src/main/java/de/winniepat/lobbyPlugin/pets/PetManager.java new file mode 100644 index 0000000..8fb4caf --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/pets/PetManager.java @@ -0,0 +1,129 @@ +package de.winniepat.lobbyPlugin.pets; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.*; + +public class PetManager implements Listener { + private final JavaPlugin plugin; + private final Map activePets = new HashMap<>(); + + public PetManager(JavaPlugin plugin) { + this.plugin = plugin; + Bukkit.getPluginManager().registerEvents(this, plugin); + } + + public JavaPlugin getPlugin() { + return plugin; + } + + public void spawnPet(Player player, EntityType type) { + UUID uuid = player.getUniqueId(); + removePet(uuid); + + Mob mob = (Mob) player.getWorld().spawnEntity(player.getLocation().add(1, 0, 1), type); + mob.setCustomName(ChatColor.GREEN + player.getName() + "'s Pet"); + mob.setCustomNameVisible(true); + mob.setAI(true); + mob.setInvulnerable(true); + mob.setCollidable(false); + + activePets.put(uuid, mob); + new FollowPlayerTask(plugin, mob, player).start(); + } + + public void removePet(UUID uuid) { + Mob mob = activePets.remove(uuid); + if (mob != null && !mob.isDead()) { + mob.remove(); + } + } + + public void removeAllPets() { + activePets.values().forEach(Entity::remove); + activePets.clear(); + } + + public void openPetSelectionGUI(Player player) { + Inventory gui = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Choose Your Pet"); + + addPetOption(gui, Material.EGG, "Chicken", EntityType.CHICKEN); + addPetOption(gui, Material.BONE, "Wolf", EntityType.WOLF); + addPetOption(gui, Material.CARROT, "Rabbit", EntityType.RABBIT); + addPetOption(gui, Material.WHITE_WOOL, "Sheep", EntityType.SHEEP); + addPetOption(gui, Material.STRING, "Cat", EntityType.CAT); + addPetOption(gui, Material.LEATHER, "Cow", EntityType.COW); + addPetOption(gui, Material.SWEET_BERRIES, "Fox", EntityType.FOX); + + ItemStack removePetItem = new ItemStack(Material.BARRIER); + ItemMeta meta = removePetItem.getItemMeta(); + meta.setDisplayName(ChatColor.RED + "Remove Pet"); + removePetItem.setItemMeta(meta); + gui.setItem(8, removePetItem); + + player.openInventory(gui); + } + + private void addPetOption(Inventory gui, Material material, String name, EntityType type) { + ItemStack item = new ItemStack(material); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.AQUA + name); + item.setItemMeta(meta); + gui.addItem(item); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + + String title = event.getView().getTitle(); + if (!title.equals(ChatColor.GREEN + "Choose Your Pet")) return; + + event.setCancelled(true); + + ItemStack clicked = event.getCurrentItem(); + if (clicked == null || !clicked.hasItemMeta()) return; + + String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); + + if (name.equalsIgnoreCase("Remove Pet")) { + removePet(player.getUniqueId()); + player.closeInventory(); + return; + } + + EntityType type = switch (name.toLowerCase()) { + case "chicken" -> EntityType.CHICKEN; + case "wolf" -> EntityType.WOLF; + case "rabbit" -> EntityType.RABBIT; + case "sheep" -> EntityType.SHEEP; + case "cat" -> EntityType.CAT; + case "cow" -> EntityType.COW; + case "fox" -> EntityType.FOX; + default -> null; + }; + + + if (type != null) { + spawnPet(player, type); + player.closeInventory(); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + UUID uuid = event.getPlayer().getUniqueId(); + removePet(uuid); + plugin.getLogger().info("[Pets] Despawned " + event.getPlayer().getName() + "'s pet."); + } +} \ No newline at end of file diff --git a/src/main/java/de/winniepat/lobbyPlugin/pets/PetSelectorGUI.java b/src/main/java/de/winniepat/lobbyPlugin/pets/PetSelectorGUI.java new file mode 100644 index 0000000..c244606 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/pets/PetSelectorGUI.java @@ -0,0 +1,57 @@ +package de.winniepat.lobbyPlugin.pets; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class PetSelectorGUI implements Listener { + + private final PetManager petManager; + + public PetSelectorGUI(PetManager petManager) { + this.petManager = petManager; + Bukkit.getPluginManager().registerEvents(this, petManager.getPlugin()); + } + + public void open(Player player) { + Inventory gui = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Choose Your Pet"); + + int index = 0; + for (PetType petType : PetType.values()) { + ItemStack item = new ItemStack(petType.getIcon()); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.AQUA + petType.getDisplayName()); + item.setItemMeta(meta); + + gui.setItem(index++, item); + } + + player.openInventory(gui); + } + + @EventHandler + public void onClick(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + + if (!event.getView().getTitle().equals(ChatColor.GREEN + "Choose Your Pet")) return; + + event.setCancelled(true); + + ItemStack clicked = event.getCurrentItem(); + if (clicked == null || !clicked.hasItemMeta()) return; + + String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); + PetType selectedPet = PetType.fromDisplayName(name); + + if (selectedPet != null) { + petManager.spawnPet(player, selectedPet.getEntityType()); + player.closeInventory(); + } + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/pets/PetType.java b/src/main/java/de/winniepat/lobbyPlugin/pets/PetType.java new file mode 100644 index 0000000..61bf1b0 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/pets/PetType.java @@ -0,0 +1,44 @@ +package de.winniepat.lobbyPlugin.pets; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; + +public enum PetType { + CHICKEN("Chicken", Material.EGG, EntityType.CHICKEN), + SHEEP("Sheep", Material.WHITE_WOOL, EntityType.SHEEP), + WOLF("Wolf", Material.BONE, EntityType.WOLF), + CAT("Cat", Material.STRING, EntityType.CAT), + COW("Cow", Material.LEATHER, EntityType.COW), + RABBIT("Rabbit", Material.RABBIT_FOOT, EntityType.RABBIT); + + private final String displayName; + private final Material icon; + private final EntityType entityType; + + PetType(String displayName, Material icon, EntityType entityType) { + this.displayName = displayName; + this.icon = icon; + this.entityType = entityType; + } + + public String getDisplayName() { + return displayName; + } + + public Material getIcon() { + return icon; + } + + public EntityType getEntityType() { + return entityType; + } + + public static PetType fromDisplayName(String name) { + for (PetType type : values()) { + if (type.displayName.equalsIgnoreCase(name)) { + return type; + } + } + return null; + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/trails/TrailGUI.java b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailGUI.java new file mode 100644 index 0000000..20778cb --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailGUI.java @@ -0,0 +1,76 @@ +package de.winniepat.lobbyPlugin.trails; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.ItemMeta; + +public class TrailGUI implements Listener { + + private final TrailManager trailManager; + private final String GUI_TITLE = ChatColor.LIGHT_PURPLE + "Select a Trail"; + + public TrailGUI(TrailManager trailManager) { + this.trailManager = trailManager; + Bukkit.getPluginManager().registerEvents(this, trailManager.getPlugin()); + } + + public void open(Player player) { + Inventory gui = Bukkit.createInventory(null, 27, GUI_TITLE); + + for (TrailType type : TrailType.values()) { + ItemStack item = new ItemStack(Material.FIREWORK_ROCKET); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.AQUA + type.getName()); + item.setItemMeta(meta); + gui.addItem(item); + } + + ItemStack removeItem = new ItemStack(Material.BARRIER); + ItemMeta removeMeta = removeItem.getItemMeta(); + removeMeta.setDisplayName(ChatColor.RED + "Remove Trail"); + removeItem.setItemMeta(removeMeta); + gui.setItem(26, removeItem); + + player.openInventory(gui); + } + + public TrailManager getTrailManager() { + return trailManager; + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + + if (!event.getView().getTitle().equals(GUI_TITLE)) return; + + event.setCancelled(true); + ItemStack clicked = event.getCurrentItem(); + if (clicked == null || !clicked.hasItemMeta()) return; + + String name = ChatColor.stripColor(clicked.getItemMeta().getDisplayName()); + + if (name.equalsIgnoreCase("Remove Trail")) { + trailManager.removeTrail(player); + player.sendMessage(ChatColor.YELLOW + "Trail removed."); + player.closeInventory(); + return; + } + + for (TrailType type : TrailType.values()) { + if (type.getName().equalsIgnoreCase(name)) { + trailManager.setTrail(player, type); + player.sendMessage(ChatColor.GREEN + "Trail set to: " + type.getName()); + break; + } + } + + player.closeInventory(); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/trails/TrailManager.java b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailManager.java new file mode 100644 index 0000000..c090ac1 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailManager.java @@ -0,0 +1,60 @@ +package de.winniepat.lobbyPlugin.trails; + +import org.bukkit.*; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.*; + +public class TrailManager { + + private final JavaPlugin plugin; + private final Map activeTrails = new HashMap<>(); + + public TrailManager(JavaPlugin plugin) { + this.plugin = plugin; + } + + public JavaPlugin getPlugin() { + return plugin; + } + + + public void setTrail(Player player, TrailType type) { + activeTrails.put(player.getUniqueId(), type); + } + + public void removeTrail(Player player) { + activeTrails.remove(player.getUniqueId()); + } + + public void startTrailTask() { + new BukkitRunnable() { + @Override + public void run() { + for (Player player : Bukkit.getOnlinePlayers()) { + TrailType type = activeTrails.get(player.getUniqueId()); + if (type == null) continue; + + Location loc = player.getLocation().add(0, 0.1, 0); + + switch (type) { + case SNOWBALL -> { + Particle.DustOptions dust = new Particle.DustOptions(Color.RED, 1.5f); + player.getWorld().spawnParticle(Particle.SNOWFLAKE, loc, 5, 0.3, 0.1, 0.3, 0, dust); + } + case NOTE -> { + for (int i = 0; i < 3; i++) { + player.getWorld().spawnParticle(Particle.NOTE, loc, 1, 0.3, 0, 0.3, 1); + } + } + default -> { + player.getWorld().spawnParticle(type.getParticle(), loc, 5, 0.3, 0.1, 0.3, 0.01); + } + } + } + } + }.runTaskTimer(plugin, 0, 10); + } +} diff --git a/src/main/java/de/winniepat/lobbyPlugin/trails/TrailType.java b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailType.java new file mode 100644 index 0000000..9f11e55 --- /dev/null +++ b/src/main/java/de/winniepat/lobbyPlugin/trails/TrailType.java @@ -0,0 +1,35 @@ +package de.winniepat.lobbyPlugin.trails; + +import org.bukkit.Particle; + +public enum TrailType { + HEART("Hearts", Particle.HEART), + FLAME("Flame", Particle.FLAME), + CLOUD("Cloud", Particle.CLOUD), + ENCHANT("Enchant", Particle.ENCHANT), + CRIT_MAGIC("Crit Magic", Particle.CRIT), + SNOWBALL("Snowball Poof", Particle.SNOWFLAKE), + WITCH("Witch Magic", Particle.WITCH), + PORTAL("Portal", Particle.PORTAL), + NOTE("Note", Particle.NOTE), + VILLAGER_HAPPY("Villager Happy", Particle.HAPPY_VILLAGER), + DRIP_WATER("Dripping Water", Particle.DRIPPING_WATER), + LAVA("Lava", Particle.LAVA), + FIREWORKS_SPARK("Firework", Particle.FIREWORK); + + private final String name; + private final Particle particle; + + TrailType(String name, Particle particle) { + this.name = name; + this.particle = particle; + } + + public String getName() { + return name; + } + + public Particle getParticle() { + return particle; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..359f62f --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,21 @@ +name: LobbyPlugin +version: '1.0' +main: de.winniepat.lobbyPlugin.LobbyPlugin +api-version: '1.21' +load: POSTWORLD +authors: [ WinniePatGG ] +description: Lobby Plugin +website: https://www.winniepat.de +commands: + spawn: + manage: + permission: lunaris.command.manage + discord: + aliases: + - dc + pet: + description: Open pet selector + trail: + permission: lunaris.command.trail + coding: + permission: lunaris.command.coding \ No newline at end of file