Compare commits

...

20 Commits
2.1 ... master

Author SHA1 Message Date
Focusvity
89b1143ab2
Adding attributes is working, remove and list doesn't 2024-06-18 18:25:32 +10:00
8a691005b8 Add placeholder files for 1.21 2024-06-15 18:19:35 -05:00
21c12f7673 Prepare for 1.20.6 2024-06-14 20:21:56 -05:00
f8d45da1ae Add 1.20.3 and 1.20.4 support 2023-12-29 19:43:45 -06:00
Focusvity
18178cd9ee
Fix wrong text color name for gray 2023-11-29 10:07:44 +11:00
55dc933dc1
Update Gradle 2023-10-09 21:02:08 -05:00
9ca82df8d4
No idea why it doesn't build on my computer 2023-10-09 20:21:41 -05:00
90bf17b3b2
Update for 1.20.2 (untested) 2023-10-08 17:04:40 -05:00
Focusvity
7254ddcce3
Fixed a NPE where an attribute name would start with minecraft: 2023-10-02 12:15:59 +11:00
Focusvity
d806ad56f2
Make the regex case insensitive 2023-09-25 16:23:22 +10:00
Focusvity
dfeaf2033d
Support legacy chat codes and minor fixes 2023-09-25 16:14:43 +10:00
57be14698f
Reformat and add missing attribute 2023-07-24 12:27:29 -05:00
a07c68e4b3
Add back 1.17.1 and 1.18.1 support 2023-07-23 14:59:05 -05:00
a7472b8b2a
Update API version 2023-07-20 20:31:14 -05:00
c77026bfda
Finish converting command to MiniMessage 2023-07-20 20:25:16 -05:00
ee441ae4b6
Convert more strings to MiniMessage 2023-07-18 15:49:02 -05:00
276e9837a2
fix relocation 2023-07-15 22:35:35 -05:00
0190098656
Fix issues and drop 1.17.1 to 1.18.1 support 2023-07-15 22:27:28 -05:00
c5aa6510d9
idk whats wrong 2023-07-15 19:15:14 -05:00
40dcb9a336
Push changes 2023-07-15 19:07:47 -05:00
49 changed files with 2366 additions and 1833 deletions

View File

@ -1,64 +1,111 @@
import xyz.jpenilla.runpaper.task.RunServer
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.github.goooler.shadow") version "8.1.7"
id("io.papermc.paperweight.userdev") version "1.7.1"
id("xyz.jpenilla.run-paper") version "2.3.0"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
}
group = "dev.plex"
version = "2.1"
subprojects {
apply(plugin = "java")
apply(plugin = "com.github.johnrengelman.shadow")
java.sourceCompatibility = JavaVersion.VERSION_17
version = "2.3"
allprojects {
repositories {
mavenCentral()
maven {
url = uri("https://repo.codemc.org/repository/nms/")
}
maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
url = uri("https://maven.playpro.com/")
content {
includeGroup("net.coreprotect")
}
}
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "io.github.goooler.shadow")
apply(plugin = "io.papermc.paperweight.userdev")
dependencies {
if (project.name != "shared") {
implementation(project(":shared"))
}
}
compileOnly("net.coreprotect:coreprotect:21.3")
tasks {
assemble {
dependsOn("reobfJar")
}
}
}
tasks {
shadowJar {
archiveBaseName.set("ItemizerX")
archiveClassifier.set("")
archiveVersion.set("")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
bukkit {
name = "ItemizerX"
version = rootProject.version.toString()
description = "A new way to edit your items"
authors = listOf("Focusvity", "Telesphoreo")
main = "dev.plex.itemizerx.ItemizerX"
apiVersion = "1.19"
foliaSupported = true
softDepend = listOf("CoreProtect")
commands {
register("itemizer") {
description = "The main command for ItemizerX"
aliases = listOf("ii", "it")
usage = "/<command>"
}
}
assemble {
dependsOn("shadowJar")
}
// Adapted from PlotSquared
val supportedVersions =
listOf("1.20.2", "1.20.4", "1.20.6", "1.21")
tasks {
supportedVersions.forEach {
register<RunServer>("runServer-$it") {
minecraftVersion(it)
pluginJars(layout.buildDirectory.file("libs/ItemizerX-${rootProject.version}.jar"))
jvmArgs("-DPaper.IgnoreJavaVersion=true", "-Dcom.mojang.eula.agree=true")
group = "run paper"
runDirectory.set(file("run-$it"))
}
}
jar {
enabled = false
assemble {
dependsOn("shadowJar")
dependsOn("reobfJar")
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(21)
}
shadowJar {
relocate("org.bstats", "dev.plex.metrics")
}
}
dependencies {
implementation(project(path = ":core", configuration = "shadow"))
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("net.coreprotect:coreprotect:22.4")
implementation("org.bstats:bstats-base:3.0.2")
implementation("org.bstats:bstats-bukkit:3.0.2")
implementation(project(path = ":shared", configuration = "shadow"))
implementation(project(path = ":v1_20_R1", configuration = "shadow"))
implementation(project(path = ":v1_19_R3", configuration = "shadow"))
implementation(project(path = ":v1_19_R2", configuration = "shadow"))
implementation(project(path = ":v1_19_R1", configuration = "shadow"))
implementation(project(path = ":v1_18_R2", configuration = "shadow"))
implementation(project(path = ":v1_18_R1", configuration = "shadow"))
implementation(project(path = ":v1_17_R1", configuration = "shadow"))
//implementation(project(path = ":v1_21_R1", configuration = "shadow"))
implementation(project(path = ":v1_20_R4", configuration = "shadow"))
implementation(project(path = ":v1_20_R3", configuration = "shadow"))
implementation(project(path = ":v1_20_R2", configuration = "shadow"))
}

View File

@ -1,11 +0,0 @@
dependencies {
implementation(project(":shared"))
implementation(project(":v1_20_R1"))
implementation(project(":v1_19_R3"))
implementation(project(":v1_19_R2"))
implementation(project(":v1_19_R1"))
implementation(project(":v1_18_R2"))
implementation(project(":v1_18_R1"))
implementation(project(":v1_17_R1"))
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
}

View File

@ -1,68 +0,0 @@
package dev.plex.itemizerx;
import org.bukkit.plugin.java.JavaPlugin;
public class ItemizerX extends JavaPlugin {
public static ItemizerX plugin;
CoreProtectBridge cpb = new CoreProtectBridge();
IAttributeManager attr;
@Override
public void onLoad() {
plugin = this;
}
@Override
public void onEnable() {
plugin = this;
cpb.getCoreProtect();
getCommand("itemizer").setExecutor(new ItemizerXCommand());
getCommand("itemizer").setTabCompleter(new ItemizerXTab());
switch (getNMSVersion()) {
case "v1_20_R1": {
attr = new dev.plex.itemizerx.v1_20_R1.AttributeManager();
return;
}
case "v1_19_R3": {
attr = new dev.plex.itemizerx.v1_19_R3.AttributeManager();
return;
}
case "v1_19_R2": {
attr = new dev.plex.itemizerx.v1_19_R2.AttributeManager();
return;
}
case "v1_19_R1": {
attr = new dev.plex.itemizerx.v1_19_R1.AttributeManager();
return;
}
case "v1_18_R2": {
attr = new dev.plex.itemizerx.v1_18_R2.AttributeManager();
return;
}
case "v1_18_R1": {
attr = new dev.plex.itemizerx.v1_18_R1.AttributeManager();
return;
}
case "v1_17_R1": {
attr = new dev.plex.itemizerx.v1_17_R1.AttributeManager();
return;
}
default: {
getLogger().severe("You are trying to run ItemizerX on an incompatible server version.");
getLogger().severe("ItemizerX only supports versions 1.17 to 1.20.1, disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
}
}
}
public String getNMSVersion() {
String v = getServer().getClass().getPackage().getName();
return v.substring(v.lastIndexOf('.') + 1);
}
@Override
public void onDisable() {
plugin = null;
}
}

View File

@ -1,14 +0,0 @@
name: ItemizerX
version: 2.1
api-version: 1.17
description: A rewrite of Itemizer
author: Focusvity, Telesphoreo
main: dev.plex.itemizerx.ItemizerX
folia-supported: true
softdepend:
- CoreProtect
commands:
itemizer:
description: The main command for ItemizerX
usage: /<command>
aliases: [ii, it]

Binary file not shown.

View File

@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

29
gradlew vendored Normal file → Executable file
View File

@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# 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"'
# 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
@ -133,10 +131,13 @@ 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.
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.
@ -144,7 +145,7 @@ 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=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
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.
# 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" \

184
gradlew.bat vendored
View File

@ -1,92 +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.
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% 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
@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.
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% 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

View File

@ -1,12 +1,10 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0")
}
rootProject.name = "ItemizerX"
include("core")
include("shared")
include("v1_20_R1")
include("v1_19_R3")
include("v1_19_R2")
include("v1_19_R1")
include("v1_18_R2")
include("v1_18_R1")
include("v1_17_R1")
//include("v1_21_R1")
include("v1_20_R4")
include("v1_20_R3")
include("v1_20_R2")

View File

@ -1,4 +1,5 @@
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
compileOnly("net.coreprotect:coreprotect:22.2")
}

View File

@ -5,17 +5,18 @@ import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
public enum Attributes {
public enum Attributes
{
MAX_HEALTH("generic.max_health", 0),
FOLLOW_RANGE("generic.follow_range", 1),
KNOCKBACK_RESISTANCE("generic.knockback_resistance", 1),
MOVEMENT_SPEED("generic.movement_speed", 1),
FLYING_SPEED("generic.flying_speed", 1),
DAMAGE("generic.attack_damage", 0),
ATTACK_KNOCKBACK("generic.attack_knockback", 0),
ATTACK_SPEED("generic.attack_speed", 1),
ARMOR("generic.armor", 0),
ARMOR_TOUGHNESS("generic.armor_toughness", 0),
FLYING_SPEED("generic.flying_speed", 1),
ATTACK_SPEED("generic.attack_speed", 1),
LUCK("generic.luck", 0),
HORSE_JUMP("horse.jump_strength", 1),
ZOMBIE_REINFORCEMENTS("zombie.spawn_reinforcements", 1);
@ -23,27 +24,34 @@ public enum Attributes {
public final String mcName;
public final int op;
Attributes(String mcName, int op) {
Attributes(String mcName, int op)
{
this.mcName = mcName;
this.op = op;
}
public static Attributes get(String name) {
for (Attributes attr : values()) {
if (attr.name().equalsIgnoreCase(name) || attr.mcName.equalsIgnoreCase(name)) {
public static Attributes get(String name)
{
for (Attributes attr : values())
{
if (attr.name().equalsIgnoreCase(name) || attr.mcName.equalsIgnoreCase(name.replace("minecraft:", "")))
{
return attr;
}
}
return null;
}
public static String getAttributes() {
public static String getAttributes()
{
return StringUtils.join(values(), ", ");
}
public static List<String> getAttributeList() {
public static List<String> getAttributeList()
{
List<String> attributes = new ArrayList<>();
for (Attributes attr : values()) {
for (Attributes attr : values())
{
attributes.add(attr.name());
}
return attributes;

View File

@ -5,40 +5,55 @@ import net.coreprotect.CoreProtectAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class CoreProtectBridge {
public class CoreProtectBridge
{
public static CoreProtect cp = null;
public static CoreProtectAPI api = null;
public static boolean logged = false;
public CoreProtect getCoreProtect() {
try {
public CoreProtect getCoreProtect()
{
try
{
final Plugin pl = Bukkit.getPluginManager().getPlugin("CoreProtect");
if (pl instanceof CoreProtect) {
if (pl instanceof CoreProtect)
{
cp = (CoreProtect) pl;
} else {
if (!logged) { // To stop the console log spam - not persistent on server restarts
}
else
{
if (!logged)
{ // To stop the console log spam - not persistent on server restarts
Bukkit.getLogger().info("CoreProtect not detected, some features will not be logged!");
logged = true;
}
}
} catch (Exception ex) {
}
catch (Exception ex)
{
ex.printStackTrace();
}
return cp;
}
public CoreProtectAPI getAPI() {
public CoreProtectAPI getAPI()
{
final CoreProtect cp = getCoreProtect();
if (cp != null && api == null) {
try {
if (cp != null && api == null)
{
try
{
api = cp.getAPI();
if (!cp.isEnabled() || !api.isEnabled()) {
if (!cp.isEnabled() || !api.isEnabled())
{
Bukkit.getLogger().info("CoreProtect is disabled, some features will not be logged!");
return null;
}
} catch (Exception ex) {
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

View File

@ -1,17 +1,28 @@
package dev.plex.itemizerx;
import net.minecraft.nbt.NBTTagList;
import java.util.Collections;
import java.util.List;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.bukkit.entity.Player;
public interface IAttributeManager {
NBTTagList getAttrList(final ItemStack item);
public interface IAttributeManager
{
default ListTag getAttrList(final ItemStack item)
{
return null;
}
default List<AttributeModifier> getAttrList(final Item item)
{
return Collections.emptyList();
}
void addAttr(final Player player, final String[] args);
void removeAttr(final Player player, final String string);
void listAttr(final Player player);
String colorize(String string);
}

View File

@ -0,0 +1,68 @@
package dev.plex.itemizerx;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class ItemizerX extends JavaPlugin
{
public static ItemizerX plugin;
CoreProtectBridge cpb = new CoreProtectBridge();
IAttributeManager attr;
@Override
public void onLoad()
{
plugin = this;
}
@Override
public void onEnable()
{
plugin = this;
// Metrics at https://bstats.org/plugin/bukkit/ItemizerX/19104
new Metrics(this, 19104);
cpb.getCoreProtect();
getCommand("itemizer").setTabCompleter(new ItemizerXTab());
switch (getServerVersion())
{
/*case "1.21" ->
{
getCommand("itemizer").setExecutor(new ItemizerXCommand());
attr = new dev.plex.itemizerx.v1_21_R1.AttributeManager();
}*/
case "1.20.5", "1.20.6" ->
{
getCommand("itemizer").setExecutor(new ItemizerXCommand());
attr = new dev.plex.itemizerx.v1_20_R4.AttributeManager();
}
case "1.20.4" ->
{
getCommand("itemizer").setExecutor(new ItemizerXCommand());
attr = new dev.plex.itemizerx.v1_20_R3.AttributeManager();
}
case "1.20.3", "1.20.2" ->
{
getCommand("itemizer").setExecutor(new ItemizerXCommand());
attr = new dev.plex.itemizerx.v1_20_R2.AttributeManager();
}
default ->
{
getLogger().severe("You are trying to run ItemizerX on an incompatible server version.");
getLogger().severe("ItemizerX only supports versions 1.20.2 to 1.21, disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
}
}
}
public String getServerVersion()
{
return Bukkit.getServer().getMinecraftVersion();
}
@Override
public void onDisable()
{
plugin = null;
}
}

View File

@ -1,5 +1,6 @@
package dev.plex.itemizerx;
public interface ItemizerXBase {
public interface ItemizerXBase
{
ItemizerX plugin = ItemizerX.plugin;
}

File diff suppressed because it is too large Load Diff

View File

@ -13,88 +13,116 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ItemizerXTab implements TabCompleter {
public class ItemizerXTab implements TabCompleter
{
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String string, String[] args) {
if (args.length == 1) {
public List<String> onTabComplete(CommandSender sender, Command cmd, String string, String[] args)
{
if (args.length == 1)
{
return Arrays.asList("help", "id", "lore", "potion", "attr", "flag", "enchant", "title", "author",
"head", "sign", "clearall");
}
if (args.length == 2) {
switch (args[0]) {
case "id": {
if (args.length == 2)
{
switch (args[0])
{
case "id":
{
List<String> materials = new ArrayList<>();
for (Material material : Material.values()) {
for (Material material : Material.values())
{
materials.add(material.name());
}
return materials;
}
case "lore": {
case "lore":
{
return Arrays.asList("add", "remove", "change", "clear");
}
case "potion": {
case "potion":
{
return Arrays.asList("add", "remove", "change", "color", "list");
}
case "attr":
case "flag":
case "enchant": {
case "enchant":
{
return Arrays.asList("add", "remove", "list", "listall");
}
default: {
default:
{
return Collections.emptyList();
}
}
}
if (args.length == 3) {
switch (args[0]) {
case "potion": {
switch (args[1]) {
if (args.length == 3)
{
switch (args[0])
{
case "potion":
{
switch (args[1])
{
case "add":
case "remove": {
case "remove":
{
List<String> potions = new ArrayList<>();
for (PotionEffectType effect : PotionEffectType.values()) {
for (PotionEffectType effect : PotionEffectType.values())
{
potions.add(effect.getName());
}
return potions;
}
}
}
case "attr": {
switch (args[1]) {
case "attr":
{
switch (args[1])
{
case "add":
case "remove": {
case "remove":
{
return Attributes.getAttributeList();
}
}
}
case "flag": {
switch (args[1]) {
case "flag":
{
switch (args[1])
{
case "add":
case "remove": {
case "remove":
{
List<String> flags = new ArrayList<>();
for (ItemFlag flag : ItemFlag.values()) {
for (ItemFlag flag : ItemFlag.values())
{
flags.add(flag.name());
}
return flags;
}
}
}
case "enchant": {
switch (args[1]) {
case "enchant":
{
switch (args[1])
{
case "add":
case "remove": {
case "remove":
{
List<String> enchantments = new ArrayList<>();
for (Enchantment enchantment : Enchantment.values()) {
for (Enchantment enchantment : Enchantment.values())
{
enchantments.add(enchantment.getKey().getKey());
}
return enchantments;
}
}
}
default: {
default:
{
return Collections.emptyList();
}
}

42
v1_17_R1/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_17_R1;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
if (attrmod == null) {
item.getTag().set("AttributeModifiers", new NBTTagList());
}
return item.getTag().getList("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.getString("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.setString("Name", args[2]);
c.setString("AttributeName", a.mcName);
c.setDouble("Amount", amount);
op = a.op;
c.setInt("Operation", op);
final Random random = new Random();
c.setIntArray("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.setString("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.getTag().set("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.getString("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.getTag().set("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_18_R1/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_18_R1;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.t().c("AttributeModifiers", 10);
if (attrmod == null) {
item.t().a("AttributeModifiers", new NBTTagList());
}
return item.t().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.t().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.t().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_18_R2/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_18_R2;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.u().c("AttributeModifiers", 10);
if (attrmod == null) {
item.u().a("AttributeModifiers", new NBTTagList());
}
return item.u().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.u().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_19_R1/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_19_R1;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.v().c("AttributeModifiers", 10);
if (attrmod == null) {
item.u().a("AttributeModifiers", new NBTTagList());
}
return item.u().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.u().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_19_R2/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_19_R2;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.v().c("AttributeModifiers", 10);
if (attrmod == null) {
item.u().a("AttributeModifiers", new NBTTagList());
}
return item.u().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.u().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_19_R3/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_19_R3;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.v().c("AttributeModifiers", 10);
if (attrmod == null) {
item.u().a("AttributeModifiers", new NBTTagList());
}
return item.u().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.u().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

42
v1_20_R1/.gitignore vendored
View File

@ -1,42 +0,0 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### 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

View File

@ -1,3 +0,0 @@
dependencies {
compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT")
}

View File

@ -1,141 +0,0 @@
package dev.plex.itemizerx.v1_20_R1;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager {
@Override
public NBTTagList getAttrList(final ItemStack item) {
NBTTagList attrmod = item.w().c("AttributeModifiers", 10);
if (attrmod == null) {
item.v().a("AttributeModifiers", new NBTTagList());
}
return item.v().c("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args) {
int op;
if (args.length < 4) {
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- "
+ "&6Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null) {
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount)) {
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (c.l("Name").equals(args[2])) {
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!"));
return;
}
}
final NBTTagCompound c = new NBTTagCompound();
c.a("Name", args[2]);
c.a("AttributeName", a.mcName);
c.a("Amount", amount);
op = a.op;
c.a("Operation", op);
final Random random = new Random();
c.a("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5) {
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase())) {
player.sendMessage(colorize("&2Supported options:\n"
+ "&e" + StringUtils.join(options, ", ")));
return;
}
c.a("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.v().a("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList();
boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
if (!c.l("Name").equals(string)) {
newList.add(nbtBase);
} else {
r = true;
}
}
if (!r) {
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.v().a("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!"));
}
@Override
public void listAttr(final Player player) {
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms);
if (attrmod.size() == 0) {
player.sendMessage(colorize("&eThis item has no attributes."));
return;
}
player.sendMessage(colorize("&2Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) {
final NBTTagCompound c = (NBTTagCompound) nbtBase;
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName
+ ", " + c.k("Amount")));
}
}
@Override
public String colorize(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

View File

@ -0,0 +1,3 @@
dependencies {
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
}

View File

@ -0,0 +1,161 @@
package dev.plex.itemizerx.v1_20_R2;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager
{
private final MiniMessage mm = MiniMessage.miniMessage();
@Override
public ListTag getAttrList(final ItemStack item)
{
ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
}
return item.getTag().getList("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args)
{
int op;
if (args.length < 4)
{
player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try
{
amount = Double.parseDouble(args[3]);
}
catch (NumberFormatException ex)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount))
{
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return;
}
}
final CompoundTag c = new CompoundTag();
c.putString("Name", args[2]);
c.putString("AttributeName", a.mcName);
c.putDouble("Amount", amount);
op = a.op;
c.putInt("Operation", op);
final Random random = new Random();
c.putIntArray("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5)
{
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase()))
{
player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return;
}
c.putString("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
final ListTag newList = new ListTag();
boolean r = false;
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase);
}
else
{
r = true;
}
}
if (!r)
{
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
}
@Override
public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0)
{
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return;
}
player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
}
}
}

View File

@ -0,0 +1,3 @@
dependencies {
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
}

View File

@ -0,0 +1,161 @@
package dev.plex.itemizerx.v1_20_R3;
import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class AttributeManager implements IAttributeManager
{
private final MiniMessage mm = MiniMessage.miniMessage();
@Override
public ListTag getAttrList(final ItemStack item)
{
ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
}
return item.getTag().getList("AttributeModifiers", 10);
}
@Override
public void addAttr(final Player player, final String[] args)
{
int op;
if (args.length < 4)
{
player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return;
}
final Attributes a = Attributes.get(args[2]);
if (a == null)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try
{
amount = Double.parseDouble(args[3]);
}
catch (NumberFormatException ex)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount))
{
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return;
}
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return;
}
}
final CompoundTag c = new CompoundTag();
c.putString("Name", args[2]);
c.putString("AttributeName", a.mcName);
c.putDouble("Amount", amount);
op = a.op;
c.putInt("Operation", op);
final Random random = new Random();
c.putIntArray("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
if (args.length == 5)
{
final List<String> options = new ArrayList<>();
options.add("mainhand");
options.add("offhand");
options.add("head");
options.add("chest");
options.add("legs");
options.add("feet");
if (!options.contains(args[4].toLowerCase()))
{
player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return;
}
c.putString("Slot", args[4].toLowerCase());
}
attrmod.add(c);
nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
final ListTag newList = new ListTag();
boolean r = false;
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase);
}
else
{
r = true;
}
}
if (!r)
{
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return;
}
nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
}
@Override
public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0)
{
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return;
}
player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
}
}
}

View File

@ -0,0 +1,3 @@
dependencies {
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
}

View File

@ -0,0 +1,158 @@
package dev.plex.itemizerx.v1_20_R4;
import dev.plex.itemizerx.IAttributeManager;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.component.ItemAttributeModifiers.Entry;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class AttributeManager implements IAttributeManager
{
private final MiniMessage mm = MiniMessage.miniMessage();
@Override
public List<AttributeModifier> getAttrList(final Item item)
{
ItemAttributeModifiers attrmod = item.components().getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
List<AttributeModifier> modifiers = new ArrayList<>();
for (Entry modifier : attrmod.modifiers())
{
modifiers.add(modifier.modifier());
}
return modifiers;
}
@Override
public void addAttr(final Player player, final String[] args)
{
if (args.length < 4)
{
player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return;
}
final Attributes_v1_20_R4 a = Attributes_v1_20_R4.get(args[2]);
if (a == null)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return;
}
double amount;
try
{
amount = Double.parseDouble(args[3]);
}
catch (NumberFormatException ex)
{
player.sendMessage(mm.deserialize("<dark_red>\"" + args[3] + "\" is not a valid number."));
return;
}
if (Double.isNaN(amount))
{
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return;
}
ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final List<AttributeModifier> attrmod = getAttrList(nms.getItem());
for (AttributeModifier modifier : attrmod)
{
if (modifier.name().equalsIgnoreCase(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return;
}
}
AtomicReference<EquipmentSlotGroup> group = new AtomicReference<>(EquipmentSlotGroup.ANY);
if (args.length == 5)
{
EquipmentSlot slot;
try
{
slot = EquipmentSlot.byName(args[4].toLowerCase());
}
catch (IllegalArgumentException ignored)
{
player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(Arrays.stream(EquipmentSlot.values()).map(s -> s.getName().toLowerCase()).toArray(), ", ")));
return;
}
group.set(EquipmentSlotGroup.bySlot(slot));
}
final AttributeModifier modifier = new AttributeModifier(a.mcName, amount, Operation.BY_ID.apply(a.op));
nms.update(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY, x ->
x.withModifierAdded(a.attributeHolder, modifier, group.get()).withTooltip(true));
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);
player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
}
@Override
public void removeAttr(final Player player, final String string)
{
/*final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final ListTag attrmod = getAttrList(nms);
final ListTag newList = new ListTag();
boolean r = false;
for (Tag nbtBase : attrmod)
{
final CompoundTag c = (CompoundTag) nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase);
}
else
{
r = true;
}
}
if (!r)
{
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return;
}
//nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is);*/
player.sendMessage(mm.deserialize("<red>Removing attributes isn't supported at the moment!"));
}
@Override
public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final List<AttributeModifier> attrmod = getAttrList(nms.getItem());
if (attrmod.isEmpty())
{
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return;
}
player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (AttributeModifier modifier : attrmod)
{
player.sendMessage(mm.deserialize("<yellow>" + modifier.name() + ", " + modifier.amount()));
}
}
}

View File

@ -0,0 +1,63 @@
package dev.plex.itemizerx.v1_20_R4;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.Holder;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.Attributes;
import org.apache.commons.lang3.StringUtils;
public enum Attributes_v1_20_R4
{
MAX_HEALTH("generic.max_health", 0, Attributes.MAX_HEALTH),
FOLLOW_RANGE("generic.follow_range", 1, Attributes.FOLLOW_RANGE),
KNOCKBACK_RESISTANCE("generic.knockback_resistance", 1, Attributes.KNOCKBACK_RESISTANCE),
MOVEMENT_SPEED("generic.movement_speed", 1, Attributes.MOVEMENT_SPEED),
FLYING_SPEED("generic.flying_speed", 1, Attributes.FLYING_SPEED),
DAMAGE("generic.attack_damage", 0, Attributes.ATTACK_DAMAGE),
ATTACK_KNOCKBACK("generic.attack_knockback", 0, Attributes.ATTACK_KNOCKBACK),
ATTACK_SPEED("generic.attack_speed", 1, Attributes.ATTACK_SPEED),
ARMOR("generic.armor", 0, Attributes.ARMOR),
ARMOR_TOUGHNESS("generic.armor_toughness", 0, Attributes.ARMOR_TOUGHNESS),
LUCK("generic.luck", 0, Attributes.LUCK),
JUMP_STRENGTH("generic.jump_strength", 1, Attributes.JUMP_STRENGTH),
ZOMBIE_REINFORCEMENTS("zombie.spawn_reinforcements", 1, Attributes.SPAWN_REINFORCEMENTS_CHANCE);
public final String mcName;
public final int op;
public final Holder<Attribute> attributeHolder;
Attributes_v1_20_R4(String mcName, int op, Holder<Attribute> attributeHolder)
{
this.mcName = mcName;
this.op = op;
this.attributeHolder = attributeHolder;
}
public static Attributes_v1_20_R4 get(String name)
{
for (Attributes_v1_20_R4 attr : values())
{
if (attr.name().equalsIgnoreCase(name) || attr.mcName.equalsIgnoreCase(name.replace("minecraft:", "")))
{
return attr;
}
}
return null;
}
public static String getAttributes()
{
return StringUtils.join(values(), ", ");
}
public static List<String> getAttributeList()
{
List<String> attributes = new ArrayList<>();
for (Attributes_v1_20_R4 attr : values())
{
attributes.add(attr.name());
}
return attributes;
}
}

View File

@ -0,0 +1,3 @@
dependencies {
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
}

View File

@ -0,0 +1,5 @@
package dev.plex.itemizerx.v1_21_R1;
public class Main
{
}