This commit is contained in:
2026-01-18 17:55:22 -06:00
commit c3bea39cd6
14 changed files with 889 additions and 0 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### IntelliJ IDEA ###
*.iws
*.iml
.idea/
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
.vscode/
.DS_Store
run/

39
build.gradle.kts Normal file
View File

@@ -0,0 +1,39 @@
plugins {
kotlin("jvm") version "2.2.21"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
id("xyz.jpenilla.run-paper") version "2.3.1"
}
group = "dev.sillyangel.more_spear_enchantments"
version = "1.1.1"
repositories {
mavenCentral()
maven {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
dependencies {
testImplementation(kotlin("test"))
paperweight.paperDevBundle("1.21.11-R0.1-SNAPSHOT")
}
kotlin {
jvmToolchain(21)
}
tasks.test {
useJUnitPlatform()
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
tasks.jar {
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
}

1
gradle.properties Normal file
View File

@@ -0,0 +1 @@
kotlin.code.style=official

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Sun Jan 18 05:01:55 UTC 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored Executable file
View File

@@ -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" "$@"

89
gradlew.bat vendored Normal file
View File

@@ -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

4
settings.gradle.kts Normal file
View File

@@ -0,0 +1,4 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
rootProject.name = "more_spear_enchantments"

View File

@@ -0,0 +1,110 @@
package dev.sillyangel.more_spear_enchantments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompatibilityCheck {
private static final Logger LOGGER = LoggerFactory.getLogger(CompatibilityCheck.class);
private static Platform platform;
private static boolean runsAsync = false;
public enum Platform {
BUKKIT,
SPIGOT,
PAPER,
FOLIA,
PURPUR
}
/**
* Gets the detected platform, performing detection on first call
*/
public static Platform getPlatform() {
if (platform == null) {
platform = checkPlatform();
LOGGER.info("Detected platform: {}", platform);
}
return platform;
}
public static boolean isRunsAsync() {
return runsAsync;
}
/**
* Checks which platform the plugin is running on by attempting to load
* platform-specific classes. Order matters - checks from most specific to least specific.
*/
private static Platform checkPlatform() {
// Check for Folia (Paper fork with regionized threading)
if (classExists("io.papermc.paper.threadedregions.RegionizedServer")) {
return Platform.FOLIA;
}
// Check for Purpur (Paper fork with extra features)
if (classExists("org.purpurmc.purpur.event.player.PlayerBookTooLargeEvent")) {
return Platform.PURPUR;
}
// Check for Paper (Spigot fork)
if (classExists("io.papermc.paper.event.player.AbstractChatEvent")) {
return Platform.PAPER;
}
// Check for Spigot (Bukkit fork)
if (classExists("org.spigotmc.CustomTimingsHandler")) {
return Platform.SPIGOT;
}
// Check for vanilla Bukkit
if (classExists("org.bukkit.Bukkit")) {
return Platform.BUKKIT;
}
throw new IllegalStateException("Unknown server platform - no recognized classes found!");
}
/**
* Helper method to safely check if a class exists
*/
private static boolean classExists(String className) {
try {
Class. forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
/**
* Determines if the plugin should continue loading based on platform compatibility.
* @return true if compatible, false if the plugin should disable itself
*/
public static boolean isCompatible() {
Platform currentPlatform = getPlatform();
switch (currentPlatform) {
case BUKKIT:
case SPIGOT:
LOGGER. error("MoreSpearEnchantments has been loaded on an installation of {}!", currentPlatform);
LOGGER.error("MoreSpearEnchantments does not support anything other than Paper and derivatives!");
LOGGER.error("Spigot is considered legacy, and you should definitely consider upgrading!");
LOGGER.error("For further information, see https://docs.papermc.io/paper/migration");
LOGGER.error("MoreSpearEnchantments will shut down now...");
return false;
case PAPER:
case PURPUR:
return true;
case FOLIA:
LOGGER.info("MoreSpearEnchantments running in Folia-compatible mode, please report any issues!");
runsAsync = true;
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,52 @@
package dev.sillyangel.more_spear_enchantments;
import dev.sillyangel.more_spear_enchantments.listeners.EnchantmentListener;
import org.bukkit.Bukkit;
import org.bukkit. event.Listener;
import org.bukkit.plugin.java. JavaPlugin;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
public class MoreSpearEnchantments extends JavaPlugin implements Listener {
public static final String PLUGIN_ID = "more_spear_enchantments";
public static final Logger LOGGER = LogUtils.getLogger();
private boolean shouldDisable = false;
@Override
public void onLoad() {
// Check platform compatibility
if (!CompatibilityCheck.isCompatible()) {
shouldDisable = true;
getServer().getPluginManager().disablePlugin(this);
return;
}
LOGGER.info("Platform check passed! Loading plugin...");
}
@Override
public void onEnable() {
// Safeguard: Don't enable if we flagged for disable
if (shouldDisable) {
LOGGER.warn("Plugin was marked for disable - skipping enable");
return;
}
// Register listeners
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new EnchantmentListener(), this);
LOGGER.info("More Spear Enchantments enabled!");
}
@Override
public void onDisable() {
// Safeguard: Don't run shutdown logic if we never fully enabled
if (shouldDisable) {
return;
}
LOGGER.info("More Spear Enchantments disabled!");
}
}

View File

@@ -0,0 +1,26 @@
package dev.sillyangel.more_spear_enchantments;
import dev.sillyangel.more_spear_enchantments.enchantment.SpearEnchantments;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.registry.event.RegistryEvents;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("UnstableApiUsage")
public class SpearEnchantmentsBootstrap implements PluginBootstrap {
@Override
public void bootstrap(@NotNull BootstrapContext context) {
context.getLogger().info("MoreSpearEnchantments bootstrap starting...");
LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
// Register enchantments during the registry compose event
manager.registerEventHandler(RegistryEvents.ENCHANTMENT.compose().newHandler(event -> {
context.getLogger().info("Registering custom enchantments...");
SpearEnchantments.registerEnchantments(event.registry());
}));
context.getLogger().info("MoreSpearEnchantments bootstrap complete!");
}
}

View File

@@ -0,0 +1,155 @@
package dev.sillyangel.more_spear_enchantments.enchantment;
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.set.RegistryKeySet;
import io.papermc.paper.registry.set.RegistrySet;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType;
@SuppressWarnings("UnstableApiUsage")
public class SpearEnchantments {
// Define enchantment keys
public static final TypedKey<Enchantment> VAMPIRIC = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "vampiric")
);
public static final TypedKey<Enchantment> EXPLOSIVE = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "explosive")
);
public static final TypedKey<Enchantment> LIGHTNING = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "lightning")
);
public static final TypedKey<Enchantment> CRIPPLING = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "crippling")
);
public static final TypedKey<Enchantment> POISON = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "poison")
);
public static final TypedKey<Enchantment> WITHERING = TypedKey.create(
RegistryKey.ENCHANTMENT,
Key.key(MoreSpearEnchantments.PLUGIN_ID, "withering")
);
public static void registerEnchantments(io.papermc.paper.registry.event.WritableRegistry<Enchantment, EnchantmentRegistryEntry.Builder> registry) {
// Create spear item key set with all spear types
RegistryKeySet<ItemType> spearItems = RegistrySet.keySet(
RegistryKey.ITEM,
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "wooden_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "stone_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "copper_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "iron_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "golden_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "diamond_spear")),
TypedKey.create(RegistryKey.ITEM, Key.key("minecraft", "netherite_spear"))
);
// Vampiric - Heals on hit
registry.register(
VAMPIRIC,
builder -> builder
.description(Component.text("Vampiric"))
.maxLevel(3)
.weight(2)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(10, 8))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(50, 8))
.anvilCost(4)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
// Explosive - Creates explosion on hit
registry.register(
EXPLOSIVE,
builder -> builder
.description(Component.text("Explosive"))
.maxLevel(3)
.weight(1)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(20, 10))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(70, 10))
.anvilCost(8)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
// Lightning - Strikes lightning on hit
registry.register(
LIGHTNING,
builder -> builder
.description(Component.text("Lightning"))
.maxLevel(3)
.weight(2)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(15, 9))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(65, 9))
.anvilCost(4)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
// Crippling - Applies slowness and weakness
registry.register(
CRIPPLING,
builder -> builder
.description(Component.text("Crippling"))
.maxLevel(3)
.weight(2)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(10, 8))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(50, 8))
.anvilCost(4)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
// Poison - Applies poison effect
registry.register(
POISON,
builder -> builder
.description(Component.text("Poison"))
.maxLevel(3)
.weight(2)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(10, 8))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(50, 8))
.anvilCost(4)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
// Withering - Applies wither effect
registry.register(
WITHERING,
builder -> builder
.description(Component.text("Withering"))
.maxLevel(3)
.weight(1)
.minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(15, 9))
.maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(65, 9))
.anvilCost(6)
.supportedItems(spearItems)
.primaryItems(spearItems)
.activeSlots(EquipmentSlotGroup.MAINHAND)
);
}
}

View File

@@ -0,0 +1,140 @@
package dev.sillyangel.more_spear_enchantments.listeners;
import dev.sillyangel.more_spear_enchantments.enchantment.SpearEnchantments;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class EnchantmentListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player)) {
return;
}
if (!(event.getEntity() instanceof LivingEntity target)) {
return;
}
ItemStack weapon = player.getInventory().getItemInMainHand();
if (weapon.isEmpty()) {
return;
}
// Get enchantments from registry
var registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
// Vampiric enchantment
Enchantment vampiric = registry.get(SpearEnchantments.VAMPIRIC);
if (vampiric != null) {
int level = weapon.getEnchantmentLevel(vampiric);
if (level > 0) {
handleVampiric(player, event.getFinalDamage(), level);
}
}
// Explosive enchantment
Enchantment explosive = registry.get(SpearEnchantments.EXPLOSIVE);
if (explosive != null) {
int level = weapon.getEnchantmentLevel(explosive);
if (level > 0) {
handleExplosive(target.getLocation(), level);
}
}
// Lightning enchantment
Enchantment lightning = registry.get(SpearEnchantments.LIGHTNING);
if (lightning != null) {
int level = weapon.getEnchantmentLevel(lightning);
if (level > 0) {
handleLightning(target, level);
}
}
// Crippling enchantment
Enchantment crippling = registry.get(SpearEnchantments.CRIPPLING);
if (crippling != null) {
int level = weapon.getEnchantmentLevel(crippling);
if (level > 0) {
handleCrippling(target, level);
}
}
// Poison enchantment
Enchantment poison = registry.get(SpearEnchantments.POISON);
if (poison != null) {
int level = weapon.getEnchantmentLevel(poison);
if (level > 0) {
handlePoison(target, level);
}
}
// Withering enchantment
Enchantment withering = registry.get(SpearEnchantments.WITHERING);
if (withering != null) {
int level = weapon.getEnchantmentLevel(withering);
if (level > 0) {
handleWithering(target, level);
}
}
}
private void handleVampiric(Player player, double damage, int level) {
// Heal based on damage dealt and level
double healAmount = damage * (0.1 * level); // 10%, 20%, 30% of damage at levels 1, 2, 3
AttributeInstance maxHealthAttr = player.getAttribute(Attribute.MAX_HEALTH);
if (maxHealthAttr == null) return;
double maxHealth = maxHealthAttr.getValue();
double newHealth = Math.min(player.getHealth() + healAmount, maxHealth);
player.setHealth(newHealth);
}
private void handleExplosive(Location location, int level) {
// Higher levels = higher chance and bigger explosion
double chance = 0.1 * level; // 10%, 20%, 30% chance at levels 1, 2, 3
if (Math.random() < chance) {
float power = 1.0f + (0.5f * level); // 1.5, 2.0, 2.5 power at levels 1, 2, 3
location.getWorld().createExplosion(location, power, false, false);
}
}
private void handleLightning(LivingEntity target, int level) {
// Strikes lightning based on level
for (int i = 0; i < level; i++) {
target.getWorld().strikeLightning(target.getLocation());
}
}
private void handleCrippling(LivingEntity target, int level) {
// Apply slowness and weakness
int duration = level * 50; // 2.5s, 5s, 7.5s at levels 1, 2, 3
target.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, duration, level - 1, false, true));
target.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, duration, level - 1, false, true));
}
private void handlePoison(LivingEntity target, int level) {
// Apply poison effect
int duration = level * 50; // 2.5s, 5s, 7.5s at levels 1, 2, 3
target.addPotionEffect(new PotionEffect(PotionEffectType.POISON, duration, level - 1, false, true));
}
private void handleWithering(LivingEntity target, int level) {
// Apply wither effect
int duration = level * 50; // 2s, 4s, 6s at levels 1, 2, 3
target.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, duration, level - 1, false, true));
}
}

View File

@@ -0,0 +1,9 @@
name: MoreSpearEnchantments
version: 1.1.0
main: dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments
bootstrapper: dev.sillyangel.more_spear_enchantments.SpearEnchantmentsBootstrap
description: more enchantments for the newly added spear from the Mounts of Mayhem update
author: sillyangel
website: https://modrinth.com/mod/more-spear-enchantments
api-version: '1.21.11'