summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2025-10-19 04:03:10 -0400
committerCarson Fleming <cflems@cflems.net>2025-10-19 04:03:10 -0400
commita3d2a1ab030a3c97dd4eb705dac8b880bcc7d8f5 (patch)
treea2cffdd33511f9f10524b8b1cdc7ed5103074efd
downloadpenguin-dust-a3d2a1ab030a3c97dd4eb705dac8b880bcc7d8f5.tar.gz
hell yea this shit works
-rw-r--r--.gitignore43
-rw-r--r--.idea/.gitignore5
-rw-r--r--.idea/codeStyles/codeStyleConfig.xml5
-rw-r--r--.idea/dictionaries/project.xml8
-rw-r--r--.idea/google-java-format.xml7
-rw-r--r--.idea/gradle.xml17
-rw-r--r--.idea/misc.xml7
-rw-r--r--build.gradle14
-rw-r--r--gradle/wrapper/gradle-wrapper.jarbin0 -> 60756 bytes
-rw-r--r--gradle/wrapper/gradle-wrapper.properties6
-rwxr-xr-xgradlew234
-rw-r--r--gradlew.bat89
-rw-r--r--settings.gradle1
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/PenguinDust.java20
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/Spell.java22
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/SpellExecutor.java8
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/exceptions/DustException.java7
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/exceptions/SpellException.java7
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/listener/CraftingListener.java111
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/listener/DamageListener.java31
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/listener/ItemUseListener.java28
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/listener/PlayerXPListener.java21
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/spells/Fireball.java18
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/spells/Lightning.java48
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/utils/DustUtils.java44
-rw-r--r--src/main/java/net/cflems/mc/penguin_dust/utils/SpellUtils.java145
-rw-r--r--src/main/resources/plugin.yml10
27 files changed, 956 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1fac4d5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,43 @@
+.gradle
+build/
+!gradle/wrapper/gradle-wrapper.jar
+!**/src/main/**/build/
+!**/src/test/**/build/
+.kotlin
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store \ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+<component name="ProjectCodeStyleConfiguration">
+ <state>
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
+ </state>
+</component> \ No newline at end of file
diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml
new file mode 100644
index 0000000..8dc826f
--- /dev/null
+++ b/.idea/dictionaries/project.xml
@@ -0,0 +1,8 @@
+<component name="ProjectDictionaryState">
+ <dictionary name="project">
+ <words>
+ <w>cflems</w>
+ <w>penguinland</w>
+ </words>
+ </dictionary>
+</component> \ No newline at end of file
diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml
new file mode 100644
index 0000000..05946a8
--- /dev/null
+++ b/.idea/google-java-format.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="GoogleJavaFormatSettings">
+ <option name="enabled" value="true" />
+ <option name="style" value="AOSP" />
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..2a65317
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="GradleMigrationSettings" migrationVersion="1" />
+ <component name="GradleSettings">
+ <option name="linkedExternalProjectsSettings">
+ <GradleProjectSettings>
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
+ <option name="gradleHome" value="" />
+ <option name="modules">
+ <set>
+ <option value="$PROJECT_DIR$" />
+ </set>
+ </option>
+ </GradleProjectSettings>
+ </option>
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..5cd9a10
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+</project> \ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..4ffdf76
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,14 @@
+apply plugin: 'java'
+group = 'net.cflems.mc'
+version = '0.0.0'
+
+repositories {
+ mavenCentral()
+ maven {url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
+}
+
+dependencies {
+ implementation 'org.spigotmc:spigot-api:1.21.9-R0.1-SNAPSHOT'
+}
+
+defaultTasks 'clean', 'build'
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..249e583
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..d7d2d57
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sat Oct 18 20:32:31 EDT 2025
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..1b6c787
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,234 @@
+#!/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/master/subprojects/plugins/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
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# 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"'
+
+# 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
+ which java >/dev/null 2>&1 || 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
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ 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
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# 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..ac1b06f
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,89 @@
+@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=.
+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%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+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%"=="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!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..15914a1
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'penguin-dust' \ No newline at end of file
diff --git a/src/main/java/net/cflems/mc/penguin_dust/PenguinDust.java b/src/main/java/net/cflems/mc/penguin_dust/PenguinDust.java
new file mode 100644
index 0000000..c24aad3
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/PenguinDust.java
@@ -0,0 +1,20 @@
+package net.cflems.mc.penguin_dust;
+
+import net.cflems.mc.penguin_dust.listener.CraftingListener;
+import net.cflems.mc.penguin_dust.listener.DamageListener;
+import net.cflems.mc.penguin_dust.listener.ItemUseListener;
+import net.cflems.mc.penguin_dust.listener.PlayerXPListener;
+
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public final class PenguinDust extends JavaPlugin {
+ @Override
+ public void onEnable() {
+ PluginManager pluginManager = getServer().getPluginManager();
+ pluginManager.registerEvents(new PlayerXPListener(), this);
+ pluginManager.registerEvents(new CraftingListener(), this);
+ pluginManager.registerEvents(new ItemUseListener(), this);
+ pluginManager.registerEvents(new DamageListener(), this);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/Spell.java b/src/main/java/net/cflems/mc/penguin_dust/Spell.java
new file mode 100644
index 0000000..5f493c5
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/Spell.java
@@ -0,0 +1,22 @@
+package net.cflems.mc.penguin_dust;
+
+import net.cflems.mc.penguin_dust.spells.Fireball;
+import net.cflems.mc.penguin_dust.spells.Lightning;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public enum Spell {
+ FIREBALL(new Fireball()),
+ LIGHTNING(new Lightning());
+
+ private final SpellExecutor executor;
+
+ Spell(SpellExecutor executor) {
+ this.executor = executor;
+ }
+
+ public boolean execute(@NotNull Player player, int strength) {
+ return executor.execute(player, strength);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/SpellExecutor.java b/src/main/java/net/cflems/mc/penguin_dust/SpellExecutor.java
new file mode 100644
index 0000000..3bc25b3
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/SpellExecutor.java
@@ -0,0 +1,8 @@
+package net.cflems.mc.penguin_dust;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public interface SpellExecutor {
+ boolean execute(@NotNull Player player, int strength);
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/exceptions/DustException.java b/src/main/java/net/cflems/mc/penguin_dust/exceptions/DustException.java
new file mode 100644
index 0000000..68907b6
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/exceptions/DustException.java
@@ -0,0 +1,7 @@
+package net.cflems.mc.penguin_dust.exceptions;
+
+public class DustException extends RuntimeException {
+ public DustException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/exceptions/SpellException.java b/src/main/java/net/cflems/mc/penguin_dust/exceptions/SpellException.java
new file mode 100644
index 0000000..1986f96
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/exceptions/SpellException.java
@@ -0,0 +1,7 @@
+package net.cflems.mc.penguin_dust.exceptions;
+
+public class SpellException extends RuntimeException {
+ public SpellException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/listener/CraftingListener.java b/src/main/java/net/cflems/mc/penguin_dust/listener/CraftingListener.java
new file mode 100644
index 0000000..1f7052c
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/listener/CraftingListener.java
@@ -0,0 +1,111 @@
+package net.cflems.mc.penguin_dust.listener;
+
+import net.cflems.mc.penguin_dust.Spell;
+import net.cflems.mc.penguin_dust.utils.DustUtils;
+import net.cflems.mc.penguin_dust.utils.SpellUtils;
+
+import org.bukkit.Material;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.inventory.PrepareItemCraftEvent;
+import org.bukkit.inventory.CraftingInventory;
+import org.bukkit.inventory.ItemStack;
+
+public final class CraftingListener implements Listener {
+ @EventHandler(priority = EventPriority.NORMAL)
+ public void onPrepareItemCraft(PrepareItemCraftEvent event) {
+ CraftingInventory craftingInventory = event.getInventory();
+ ItemStack extraneousItem = null;
+ int dustCount = 0, blazePowderCount = 0, copperIngotCount = 0;
+
+ for (ItemStack item : craftingInventory.getMatrix()) {
+ if (item == null) continue;
+
+ switch (item.getType()) {
+ case BLAZE_POWDER:
+ blazePowderCount += item.getAmount();
+ break;
+ case COPPER_INGOT:
+ copperIngotCount += item.getAmount();
+ break;
+ case PUMPKIN_SEEDS:
+ if (DustUtils.isDust(item)) {
+ dustCount += item.getAmount();
+ break;
+ }
+ default:
+ if (item.getAmount() != 1 || extraneousItem != null) return;
+ extraneousItem = item;
+ }
+ }
+
+ if (dustCount <= 0) return;
+ if (extraneousItem == null || (blazePowderCount > 0 && copperIngotCount > 0)) {
+ craftingInventory.setResult(null);
+ return;
+ }
+
+ ItemStack enchantedItem = extraneousItem.clone();
+ boolean success;
+ if (blazePowderCount > 0) {
+ success =
+ SpellUtils.addSpell(
+ enchantedItem,
+ Spell.FIREBALL,
+ dustCount,
+ Math.min(blazePowderCount, dustCount));
+ } else if (copperIngotCount > 0) {
+ success =
+ SpellUtils.addSpell(
+ enchantedItem,
+ Spell.LIGHTNING,
+ dustCount,
+ Math.min(copperIngotCount, dustCount));
+ } else {
+ success = SpellUtils.reloadSpell(enchantedItem, dustCount);
+ }
+
+ if (success) craftingInventory.setResult(enchantedItem);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onInventoryClick(InventoryClickEvent event) {
+ if (!(event.getClickedInventory() instanceof CraftingInventory craftingInventory)
+ || event.getSlotType() != InventoryType.SlotType.RESULT) return;
+ int dustCount = 0, blazePowderCount = 0, copperIngotCount = 0;
+
+ for (ItemStack stack : craftingInventory.getMatrix()) {
+ if (stack == null) continue;
+ switch (stack.getType()) {
+ case BLAZE_POWDER:
+ blazePowderCount += stack.getAmount();
+ stack.setAmount(0);
+ break;
+ case COPPER_INGOT:
+ copperIngotCount += stack.getAmount();
+ stack.setAmount(0);
+ break;
+ case PUMPKIN_SEEDS:
+ if (DustUtils.isDust(stack)) {
+ dustCount += stack.getAmount();
+ stack.setAmount(0);
+ }
+ break;
+ }
+ }
+
+ if (blazePowderCount - dustCount > 0) {
+ event.getWhoClicked()
+ .getInventory()
+ .addItem(new ItemStack(Material.BLAZE_POWDER, blazePowderCount - dustCount));
+ }
+ if (copperIngotCount - dustCount > 0) {
+ event.getWhoClicked()
+ .getInventory()
+ .addItem(new ItemStack(Material.COPPER_INGOT, copperIngotCount - dustCount));
+ }
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/listener/DamageListener.java b/src/main/java/net/cflems/mc/penguin_dust/listener/DamageListener.java
new file mode 100644
index 0000000..5e8a35e
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/listener/DamageListener.java
@@ -0,0 +1,31 @@
+package net.cflems.mc.penguin_dust.listener;
+
+import com.google.common.collect.MoreCollectors;
+
+import net.cflems.mc.penguin_dust.PenguinDust;
+import net.cflems.mc.penguin_dust.utils.SpellUtils;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.metadata.MetadataValue;
+
+import java.util.List;
+import java.util.Optional;
+
+public final class DamageListener implements Listener {
+ @EventHandler(priority = EventPriority.NORMAL)
+ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
+ Entity damager = event.getDamager();
+ List<MetadataValue> damageMetadata = damager.getMetadata(SpellUtils.DAMAGE_KEY);
+ Optional<MetadataValue> damageValue =
+ damageMetadata.stream()
+ .filter(md -> md.getOwningPlugin() instanceof PenguinDust)
+ .collect(MoreCollectors.toOptional());
+ if (damageValue.isEmpty()) return;
+
+ event.setDamage(damageValue.get().asInt());
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/listener/ItemUseListener.java b/src/main/java/net/cflems/mc/penguin_dust/listener/ItemUseListener.java
new file mode 100644
index 0000000..3dcf2c0
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/listener/ItemUseListener.java
@@ -0,0 +1,28 @@
+package net.cflems.mc.penguin_dust.listener;
+
+import net.cflems.mc.penguin_dust.utils.SpellUtils;
+
+import org.bukkit.event.Event;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.Set;
+
+public final class ItemUseListener implements Listener {
+ private static final Set<Action> TARGET_ACTIONS =
+ Set.of(Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK);
+
+ @EventHandler(priority = EventPriority.NORMAL)
+ public void onPlayerInteract(PlayerInteractEvent event) {
+ ItemStack itemInHand = event.getItem();
+ if (itemInHand == null
+ || event.useItemInHand().equals(Event.Result.DENY)
+ || !TARGET_ACTIONS.contains(event.getAction())) return;
+
+ if (SpellUtils.invokeSpell(event.getPlayer(), itemInHand)) event.setCancelled(true);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/listener/PlayerXPListener.java b/src/main/java/net/cflems/mc/penguin_dust/listener/PlayerXPListener.java
new file mode 100644
index 0000000..2ef7b6f
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/listener/PlayerXPListener.java
@@ -0,0 +1,21 @@
+package net.cflems.mc.penguin_dust.listener;
+
+import net.cflems.mc.penguin_dust.utils.DustUtils;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerExpChangeEvent;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+
+public final class PlayerXPListener implements Listener {
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerExpChange(@NotNull PlayerExpChangeEvent event) {
+ if (event.getAmount() < 1) return;
+
+ ItemStack dust = DustUtils.createDust(event.getAmount());
+ event.getPlayer().getInventory().addItem(dust);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/spells/Fireball.java b/src/main/java/net/cflems/mc/penguin_dust/spells/Fireball.java
new file mode 100644
index 0000000..ca96609
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/spells/Fireball.java
@@ -0,0 +1,18 @@
+package net.cflems.mc.penguin_dust.spells;
+
+import net.cflems.mc.penguin_dust.SpellExecutor;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public final class Fireball implements SpellExecutor {
+ private static final float MAX_YIELD = 128f;
+
+ @Override
+ public boolean execute(@NotNull Player player, int strength) {
+ org.bukkit.entity.Fireball fireball =
+ player.launchProjectile(org.bukkit.entity.Fireball.class);
+ fireball.setYield(Math.min(strength / 2.0f, MAX_YIELD));
+ return true;
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/spells/Lightning.java b/src/main/java/net/cflems/mc/penguin_dust/spells/Lightning.java
new file mode 100644
index 0000000..610921d
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/spells/Lightning.java
@@ -0,0 +1,48 @@
+package net.cflems.mc.penguin_dust.spells;
+
+import net.cflems.mc.penguin_dust.PenguinDust;
+import net.cflems.mc.penguin_dust.SpellExecutor;
+import net.cflems.mc.penguin_dust.utils.SpellUtils;
+
+import org.bukkit.FluidCollisionMode;
+import org.bukkit.World;
+import org.bukkit.entity.LightningStrike;
+import org.bukkit.entity.Player;
+import org.bukkit.metadata.FixedMetadataValue;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.util.RayTraceResult;
+import org.jetbrains.annotations.NotNull;
+
+public final class Lightning implements SpellExecutor {
+ private static final int MAX_DISTANCE = 128;
+
+ @Override
+ public boolean execute(@NotNull Player player, int strength) {
+ World world = player.getWorld();
+ RayTraceResult rayTraceResult =
+ world.rayTrace(
+ player.getEyeLocation(),
+ player.getEyeLocation().getDirection(),
+ MAX_DISTANCE,
+ FluidCollisionMode.NEVER,
+ true,
+ 0,
+ entity -> !player.equals(entity));
+ if (rayTraceResult == null) return false;
+
+ LightningStrike lightningStrike =
+ world.strikeLightning(rayTraceResult.getHitPosition().toLocation(world));
+ lightningStrike.setCausingPlayer(player);
+
+ JavaPlugin providingPlugin = JavaPlugin.getProvidingPlugin(PenguinDust.class);
+ lightningStrike.setMetadata(
+ SpellUtils.DAMAGE_KEY,
+ new FixedMetadataValue(providingPlugin, calculateDamage(strength)));
+ return true;
+ }
+
+ private static int calculateDamage(int spellStrength) {
+ double spellDamage = spellStrength * Math.sqrt(spellStrength) / 8.0;
+ return (int) spellDamage;
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/utils/DustUtils.java b/src/main/java/net/cflems/mc/penguin_dust/utils/DustUtils.java
new file mode 100644
index 0000000..55e06e5
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/utils/DustUtils.java
@@ -0,0 +1,44 @@
+package net.cflems.mc.penguin_dust.utils;
+
+import com.google.common.base.Preconditions;
+
+import net.cflems.mc.penguin_dust.exceptions.DustException;
+
+import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataType;
+import org.jetbrains.annotations.NotNull;
+
+public final class DustUtils {
+ private static final NamespacedKey IS_DUST_KEY =
+ Preconditions.checkNotNull(NamespacedKey.fromString("penguin-dust:is-penguin-dust"));
+
+ private DustUtils() {}
+
+ @NotNull
+ public static ItemStack createDust(int amount) {
+ if (amount <= 0) throw new DustException("Cannot have zero dust");
+
+ ItemStack base = new ItemStack(Material.PUMPKIN_SEEDS, amount);
+ ItemMeta meta =
+ Preconditions.checkNotNull(
+ base.getItemMeta(), "this plugin doesn't work if we can't set metadata");
+ meta.setItemName("Penguin Dust");
+ meta.getPersistentDataContainer().set(IS_DUST_KEY, PersistentDataType.BOOLEAN, true);
+
+ if (!base.setItemMeta(meta)) throw new DustException("Failed to set dust metadata");
+ return base;
+ }
+
+ public static boolean isDust(@NotNull ItemStack itemStack) {
+ if (itemStack.getType() != Material.PUMPKIN_SEEDS) return false;
+
+ ItemMeta meta = itemStack.getItemMeta();
+ if (meta == null) return false;
+
+ return meta.getPersistentDataContainer()
+ .getOrDefault(IS_DUST_KEY, PersistentDataType.BOOLEAN, false);
+ }
+}
diff --git a/src/main/java/net/cflems/mc/penguin_dust/utils/SpellUtils.java b/src/main/java/net/cflems/mc/penguin_dust/utils/SpellUtils.java
new file mode 100644
index 0000000..7b9d166
--- /dev/null
+++ b/src/main/java/net/cflems/mc/penguin_dust/utils/SpellUtils.java
@@ -0,0 +1,145 @@
+package net.cflems.mc.penguin_dust.utils;
+
+import com.google.common.base.Preconditions;
+
+import net.cflems.mc.penguin_dust.Spell;
+import net.cflems.mc.penguin_dust.exceptions.SpellException;
+
+import org.bukkit.NamespacedKey;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.persistence.PersistentDataContainer;
+import org.bukkit.persistence.PersistentDataType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public final class SpellUtils {
+ public static final String DAMAGE_KEY = "penguin-dust:damage";
+ private static final NamespacedKey SPELL_NAME_KEY =
+ Preconditions.checkNotNull(NamespacedKey.fromString("penguin-dust:spell"));
+ private static final NamespacedKey SPELL_REMAINING_CAPACITY_KEY =
+ Preconditions.checkNotNull(
+ NamespacedKey.fromString("penguin-dust:spell-remaining-capacity"));
+ private static final NamespacedKey SPELL_MAX_CAPACITY_KEY =
+ Preconditions.checkNotNull(NamespacedKey.fromString("penguin-dust:spell-max-capacity"));
+ private static final NamespacedKey SPELL_THROUGHPUT_KEY =
+ Preconditions.checkNotNull(NamespacedKey.fromString("penguin-dust:spell-throughput"));
+
+ private SpellUtils() {}
+
+ public static boolean invokeSpell(@NotNull Player player, @NotNull ItemStack itemStack) {
+ ItemMeta meta = itemStack.getItemMeta();
+ if (meta == null) return false;
+
+ SpellData spellData = getSpellData(meta);
+ if (spellData == null) return false;
+
+ int spellStrength = Math.min(spellData.remainingCapacity, spellData.throughput);
+
+ if (!spellData.spell.execute(player, spellStrength)) return false;
+
+ int newRemainingCapacity = Math.max(spellData.remainingCapacity - spellStrength, 0);
+
+ if (newRemainingCapacity == 0) {
+ player.getInventory().remove(itemStack);
+ } else {
+ meta.getPersistentDataContainer()
+ .set(
+ SPELL_REMAINING_CAPACITY_KEY,
+ PersistentDataType.INTEGER,
+ newRemainingCapacity);
+
+ setLore(
+ meta,
+ spellData.spell,
+ spellData.throughput,
+ newRemainingCapacity,
+ spellData.maxCapacity);
+
+ if (!itemStack.setItemMeta(meta))
+ throw new SpellException("Failed to set spell metadata");
+ }
+
+ return true;
+ }
+
+ public static boolean addSpell(
+ @NotNull ItemStack itemStack, @NotNull Spell spell, int maxCapacity, int throughput) {
+ ItemMeta meta = itemStack.getItemMeta();
+ if (meta == null) return false;
+
+ PersistentDataContainer persistentDataContainer = meta.getPersistentDataContainer();
+ persistentDataContainer.set(SPELL_NAME_KEY, PersistentDataType.STRING, spell.toString());
+ persistentDataContainer.set(
+ SPELL_REMAINING_CAPACITY_KEY, PersistentDataType.INTEGER, maxCapacity);
+ persistentDataContainer.set(
+ SPELL_MAX_CAPACITY_KEY, PersistentDataType.INTEGER, maxCapacity);
+ persistentDataContainer.set(SPELL_THROUGHPUT_KEY, PersistentDataType.INTEGER, throughput);
+
+ setLore(meta, spell, throughput, maxCapacity, maxCapacity);
+ return itemStack.setItemMeta(meta);
+ }
+
+ public static boolean reloadSpell(@NotNull ItemStack itemStack, int additionalCapacity) {
+ ItemMeta meta = itemStack.getItemMeta();
+ if (meta == null) return false;
+
+ SpellData spellData = getSpellData(meta);
+ if (spellData == null) return false;
+
+ int newRemainingCapacity = spellData.remainingCapacity + additionalCapacity;
+ int newMaxCapacity = Math.max(newRemainingCapacity, spellData.maxCapacity);
+
+ PersistentDataContainer persistentDataContainer = meta.getPersistentDataContainer();
+ persistentDataContainer.set(
+ SPELL_REMAINING_CAPACITY_KEY, PersistentDataType.INTEGER, newRemainingCapacity);
+ persistentDataContainer.set(
+ SPELL_MAX_CAPACITY_KEY, PersistentDataType.INTEGER, newMaxCapacity);
+
+ setLore(meta, spellData.spell, spellData.throughput, newRemainingCapacity, newMaxCapacity);
+ return itemStack.setItemMeta(meta);
+ }
+
+ private record SpellData(
+ @NotNull Spell spell, int throughput, int remainingCapacity, int maxCapacity) {}
+
+ @Nullable
+ private static SpellData getSpellData(@NotNull ItemMeta meta) {
+ PersistentDataContainer persistentDataContainer = meta.getPersistentDataContainer();
+
+ String spellName = persistentDataContainer.get(SPELL_NAME_KEY, PersistentDataType.STRING);
+ if (spellName == null) return null;
+ Spell spell = Spell.valueOf(spellName);
+
+ Integer throughput =
+ persistentDataContainer.get(SPELL_THROUGHPUT_KEY, PersistentDataType.INTEGER);
+ if (throughput == null) return null;
+
+ Integer remainingCapacity =
+ persistentDataContainer.get(
+ SPELL_REMAINING_CAPACITY_KEY, PersistentDataType.INTEGER);
+ if (remainingCapacity == null) return null;
+
+ Integer maxCapacity =
+ persistentDataContainer.get(SPELL_MAX_CAPACITY_KEY, PersistentDataType.INTEGER);
+ if (maxCapacity == null) return null;
+
+ return new SpellData(spell, throughput, remainingCapacity, maxCapacity);
+ }
+
+ private static void setLore(
+ @NotNull ItemMeta meta,
+ @NotNull Spell spell,
+ int throughput,
+ int remainingCapacity,
+ int maxCapacity) {
+ meta.setLore(
+ List.of(
+ "Enchanted with: " + spell,
+ "Magical Durability: " + remainingCapacity + "/" + maxCapacity,
+ "Spell Strength: " + throughput));
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..29ab7d6
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,10 @@
+name: PenguinDust
+website: https://penguinland.io/penguindust
+author: cflems
+version: 0.0.0
+description: Brings magic to Penguinland with PenguinDust.
+main: net.cflems.mc.penguin_dust.PenguinDust
+load: POSTWORLD
+api-version: '1.21.9'
+depend: []
+commands: {}