9
0
mirror of https://github.com/PSYCHEER/VanillaCustomizer.git synced 2025-12-19 15:09:17 +00:00
LoneDev
2024-09-04 16:19:23 +02:00
parent 9d5ee5ac1d
commit 13f3cd1f00
62 changed files with 803 additions and 774 deletions

BIN
.assets/banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
.assets/banner_big.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
.assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

BIN
.assets/product_page.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

2
.gitattributes vendored
View File

@@ -1,2 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto

8
.gitignore vendored
View File

@@ -111,9 +111,9 @@ buildNumber.properties
# Common working directory # Common working directory
run/ run/
# My stuff
/.cache/ /.cache/
/output/
/.paper-nms/ /.paper-nms/
/custom_mapping.txt /output/
/.assets/
target

View File

@@ -1 +0,0 @@
echo f | xcopy C:\Progetti\Minecraft\Spigot\VanillaCustomizer\output\VanillaCustomizer.jar C:\Progetti\Minecraft\TestServer\blank_template\1.20\plugins\VanillaCustomizer.jar /Y

View File

@@ -5,13 +5,14 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<repositories> <repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@@ -25,34 +26,71 @@
<url>https://oss.sonatype.org/content/groups/public</url> <url>https://oss.sonatype.org/content/groups/public</url>
</repository> </repository>
<repository> <repository>
<id>dmulloy2-repo</id> <id>sonatype</id>
<url>https://repo.dmulloy2.net/repository/public/</url> <url>https://oss.sonatype.org/content/groups/public/</url>
</repository> </repository>
<repository> <repository>
<id>matteodev</id> <id>papermc</id>
<url>https://www.matteodev.it/spigot/public/maven/</url> <url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>codemc</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.20-R0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version> <version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone.LoneLibs</groupId>
<artifactId>LoneLibs</artifactId> <artifactId>LoneLibs</artifactId>
<version>1.0.50</version> <version>1.0</version>
<scope>system</scope>
<systemPath>${jars_libs_folder}/LoneLibs.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>libs</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>5.1.0</version> <version>1.0</version>
<scope>provided</scope> <scope>system</scope>
<systemPath>${jars_libs_folder}/ProtocolLib.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -1,8 +1,11 @@
package dev.lone.vanillacustomizer; package dev.lone.vanillacustomizer;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import dev.lone.vanillacustomizer.customization.rules.RuleVanillaItemMatcher; import dev.lone.vanillacustomizer.customization.rules.RuleVanillaItemMatcher;
import dev.lone.vanillacustomizer.nms.NMS;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@@ -10,20 +13,23 @@ import org.bukkit.inventory.meta.ItemMeta;
public class ChangeSession public class ChangeSession
{ {
public final ItemStack item; public final ItemStack item;
private final Player player;
public final ItemStack originalItem; public final ItemStack originalItem;
public ItemMeta meta; public ItemMeta meta;
public NBTItem nbt; public NBTItem nbtLegacy;
public NItem nbt;
public final boolean isVanilla; public final boolean isVanilla;
@Nullable @Nullable
private Boolean hasChanged_cached; private Boolean hasChanged_cached;
public ChangeSession(ItemStack item, boolean trackChanges) public ChangeSession(ItemStack item, Player player, boolean trackChanges)
{ {
this.item = item; this.item = item;
this.player = player;
if(trackChanges) if(trackChanges)
this.originalItem = item.clone(); this.originalItem = item.clone();
else else
@@ -32,6 +38,11 @@ public class ChangeSession
isVanilla = RuleVanillaItemMatcher.satisfy(item); isVanilla = RuleVanillaItemMatcher.satisfy(item);
} }
public Player getPlayer()
{
return player;
}
public ItemMeta refreshMeta() public ItemMeta refreshMeta()
{ {
// Meta always needs to be refreshed as Spigot caches it! // Meta always needs to be refreshed as Spigot caches it!
@@ -39,16 +50,26 @@ public class ChangeSession
return meta; return meta;
} }
private void refreshNbt() private void refreshNBT()
{ {
nbt = new NBTItem(item); nbtLegacy = new NBTItem(item);
if(NMS.is_v1_1_20_5_or_greater)
nbt = new NItem(item);
} }
public NBTItem nbt() public NBTItem nbtLegacy()
{
if(nbtLegacy != null)
return nbtLegacy;
refreshNBT();
return nbtLegacy;
}
public NItem nbt()
{ {
if(nbt != null) if(nbt != null)
return nbt; return nbt;
refreshNbt(); refreshNBT();
return nbt; return nbt;
} }
@@ -59,12 +80,14 @@ public class ChangeSession
public void saveNbt() public void saveNbt()
{ {
// nbt.saveMetaChanges(); // TODO: idk if I need to somehow save the data or not, probably new NBT api lib doesn't require it anymore. // nbt.saveMetaChanges(); // TODO: idk if I need to somehow save the data or not, probably new NBT api lib doesn't require it anymore.
if(nbt != null)
nbt.save();
} }
public void applyMeta() public void applyMeta()
{ {
this.item.setItemMeta(this.meta); this.item.setItemMeta(this.meta);
refreshNbt(); refreshNBT();
} }
public boolean hasChanged() public boolean hasChanged()
@@ -80,7 +103,7 @@ public class ChangeSession
public void refreshAll() public void refreshAll()
{ {
refreshNbt(); refreshNBT();
refreshMeta(); refreshMeta();
} }
} }

View File

@@ -2,7 +2,8 @@ package dev.lone.vanillacustomizer;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import dev.lone.LoneLibs.annotations.Nullable; import dev.lone.vanillacustomizer.exception.InvalidCustomizationPropertyException;
import org.jetbrains.annotations.Nullable;
import dev.lone.vanillacustomizer.api.VanillaCustomizerApi; import dev.lone.vanillacustomizer.api.VanillaCustomizerApi;
import dev.lone.vanillacustomizer.commands.registered.MainCommand; import dev.lone.vanillacustomizer.commands.registered.MainCommand;
import dev.lone.vanillacustomizer.customization.changes.*; import dev.lone.vanillacustomizer.customization.changes.*;
@@ -39,13 +40,21 @@ public class Customizations
{ {
ConfigFile config = new ConfigFile(Main.inst(), false, file.toPath().toString(), false, false); ConfigFile config = new ConfigFile(Main.inst(), false, file.toPath().toString(), false, false);
ConfigurationSection cosmeticsSection = config.getConfigurationSection("customizations"); boolean ignoreInventoriesEnabled = config.getBoolean("settings.ignore_inventories.enabled");
if (cosmeticsSection == null) // File has no rules boolean ignoreAnyCustomInventory = ignoreInventoriesEnabled && config.getBoolean("settings.ignore_inventories.any_custom", false);
List<String> ignoreInventoriesByTitle = ignoreInventoriesEnabled ? config.getStringList("settings.ignore_inventories.by_title"): null;
ConfigurationSection customizationsSection = config.getConfigurationSection("customizations");
if (customizationsSection == null) // File has no rules
continue; continue;
for (String key : cosmeticsSection.getKeys(false)) for (String key : customizationsSection.getKeys(false))
{ {
Customization customization = new Customization(); Customization customization = new Customization(
ignoreInventoriesEnabled,
ignoreAnyCustomInventory,
ignoreInventoriesByTitle
);
ConfigurationSection section = config.getConfigurationSection("customizations." + key); ConfigurationSection section = config.getConfigurationSection("customizations." + key);
assert section != null; assert section != null;
@@ -169,7 +178,7 @@ public class Customizations
} }
catch (Throwable ex) catch (Throwable ex)
{ {
if(ex instanceof InvalidCustomizationPropertyExtension) if(ex instanceof InvalidCustomizationPropertyException)
{ {
Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath()); Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath());
Main.msg.error(ex.getMessage()); Main.msg.error(ex.getMessage());
@@ -282,10 +291,10 @@ public class Customizations
} }
else if (tmp.length == 2) else if (tmp.length == 2)
{ {
if (Utilz.isNumeric(tmp[1])) if (Utils.isNumeric(tmp[1]))
{ {
enchant = Enchantment.getByName(tmp[0]); enchant = Enchantment.getByName(tmp[0]);
enchantLevel = Utilz.parseInt(tmp[1], 1); enchantLevel = Utils.parseInt(tmp[1], 1);
if (enchant == null) if (enchant == null)
enchant = Enchantment.getByKey(NamespacedKey.minecraft(tmp[0])); enchant = Enchantment.getByKey(NamespacedKey.minecraft(tmp[0]));
@@ -298,7 +307,7 @@ public class Customizations
else if (tmp.length == 3) else if (tmp.length == 3)
{ {
enchant = Enchantment.getByKey(new NamespacedKey(tmp[0], tmp[1])); enchant = Enchantment.getByKey(new NamespacedKey(tmp[0], tmp[1]));
enchantLevel = Utilz.parseInt(tmp[2], 1); enchantLevel = Utils.parseInt(tmp[2], 1);
} }
enchants.put(enchant, enchantLevel); enchants.put(enchant, enchantLevel);
@@ -324,7 +333,7 @@ public class Customizations
} }
else if (tmp.length == 2) else if (tmp.length == 2)
{ {
if (Utilz.isNumeric(tmp[1])) if (Utils.isNumeric(tmp[1]))
{ {
enchant = Enchantment.getByName(tmp[0]); enchant = Enchantment.getByName(tmp[0]);
if (enchant == null) if (enchant == null)
@@ -360,11 +369,11 @@ public class Customizations
throwInvalidConfig(); throwInvalidConfig();
@Nullable String attributeStr = getStringOrThrow(attributeSection, "attribute"); @Nullable String attributeStr = getStringOrThrow(attributeSection, "attribute");
Attribute attribute = Utilz.strToAttributeType(attributeStr); Attribute attribute = Utils.strToAttributeType(attributeStr);
if (attribute == null) if (attribute == null)
throwInvalidPropertyValue("attribute"); throwInvalidPropertyValue("attribute");
@Nullable String slotStr = getStringOrThrow(attributeSection, "slot"); @Nullable String slotStr = getStringOrThrow(attributeSection, "slot");
EquipmentSlot slot = Utilz.strToVanillaEquipmentSlot(slotStr); EquipmentSlot slot = Utils.strToVanillaEquipmentSlot(slotStr);
if (slot == null) if (slot == null)
throwInvalidPropertyValue("slot"); throwInvalidPropertyValue("slot");
@@ -422,7 +431,7 @@ public class Customizations
} }
catch (Throwable ex) catch (Throwable ex)
{ {
if(ex instanceof InvalidCustomizationPropertyExtension) if(ex instanceof InvalidCustomizationPropertyException)
{ {
Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath()); Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath());
Main.msg.error(ex.getMessage()); Main.msg.error(ex.getMessage());
@@ -451,22 +460,22 @@ public class Customizations
private void throwInvalidConfig() private void throwInvalidConfig()
{ {
throw new InvalidCustomizationPropertyExtension("Invalid configuration. Please check the tutorials."); throw new InvalidCustomizationPropertyException("Invalid configuration. Please check the tutorials.");
} }
private void throwMissingProperty(String name) private void throwMissingProperty(String name)
{ {
throw new InvalidCustomizationPropertyExtension("Missing property '" + name + "'."); throw new InvalidCustomizationPropertyException("Missing property '" + name + "'.");
} }
private void throwInvalidPropertyValue(String name) private void throwInvalidPropertyValue(String name)
{ {
throw new InvalidCustomizationPropertyExtension("Invalid value for property '" + name + "'."); throw new InvalidCustomizationPropertyException("Invalid value for property '" + name + "'.");
} }
private void throwInvalidPropertyValue(String name, String value) private void throwInvalidPropertyValue(String name, String value)
{ {
throw new InvalidCustomizationPropertyExtension("Invalid value for property '" + name + "' -> '" + value + "'."); throw new InvalidCustomizationPropertyException("Invalid value for property '" + name + "' -> '" + value + "'.");
} }
public void handle(ItemStack itemStack, Player player) public void handle(ItemStack itemStack, Player player)
@@ -475,7 +484,7 @@ public class Customizations
return; return;
boolean trackChanges = MainCommand.hasDebugTag(player); boolean trackChanges = MainCommand.hasDebugTag(player);
ChangeSession session = new ChangeSession(itemStack, trackChanges); ChangeSession session = new ChangeSession(itemStack, player, trackChanges);
for (Map.Entry<String, Customization> entry : customizations.entrySet()) for (Map.Entry<String, Customization> entry : customizations.entrySet())
{ {
Customization customization = entry.getValue(); Customization customization = entry.getValue();

View File

@@ -1,9 +0,0 @@
package dev.lone.vanillacustomizer;
public class InvalidCustomizationPropertyExtension extends IllegalArgumentException
{
public InvalidCustomizationPropertyExtension(String text)
{
super(text);
}
}

View File

@@ -27,6 +27,7 @@ public final class Main extends JavaPlugin implements Listener
// https://game8.co/games/Minecraft/archives/378457#hl_1 // https://game8.co/games/Minecraft/archives/378457#hl_1
//DO NOT SET AS "final" OR SPIGOT.MC won't replace it. //DO NOT SET AS "final" OR SPIGOT.MC won't replace it.
@SuppressWarnings("unused")
public static String b = "%%__USER__%%"; public static String b = "%%__USER__%%";
public static Msg msg; public static Msg msg;

View File

@@ -1,6 +1,6 @@
package dev.lone.vanillacustomizer.commands; package dev.lone.vanillacustomizer.commands;
import dev.lone.LoneLibs.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.bukkit.command.*; import org.bukkit.command.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;

View File

@@ -1,10 +1,10 @@
package dev.lone.vanillacustomizer.commands.registered; package dev.lone.vanillacustomizer.commands.registered;
import dev.lone.LoneLibs.annotations.NotNull;
import dev.lone.vanillacustomizer.Main; import dev.lone.vanillacustomizer.Main;
import dev.lone.vanillacustomizer.commands.CommandRun; import dev.lone.vanillacustomizer.commands.CommandRun;
import dev.lone.vanillacustomizer.utils.SmallCaps; import dev.lone.vanillacustomizer.utils.SmallCaps;
import fr.mrmicky.fastinv.FastInv; import fr.mrmicky.fastinv.FastInv;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -58,7 +58,11 @@ public class MainCommand extends CommandRun
break; break;
case "small": case "small":
if(args.length < 2)
{
Main.msg.send(player, "Usage: /vanillacustomizer small <text>");
return;
}
String text = args[1]; String text = args[1];
Main.msg.send(player, SmallCaps.apply(text)); Main.msg.send(player, SmallCaps.apply(text));
break; break;
@@ -130,6 +134,8 @@ public class MainCommand extends CommandRun
@Override @Override
public List<String> onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, @NotNull String[] args) public List<String> onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, @NotNull String[] args)
{ {
return List.of("reload", "showdebugtag", "small", "debugmenu"); if(args.length == 1)
return List.of("reload", "showdebugtag", "small", "debugmenu");
return List.of();
} }
} }

View File

@@ -3,16 +3,29 @@ package dev.lone.vanillacustomizer.customization;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.vanillacustomizer.customization.changes.IChange; import dev.lone.vanillacustomizer.customization.changes.IChange;
import dev.lone.vanillacustomizer.customization.rules.IRule; import dev.lone.vanillacustomizer.customization.rules.IRule;
import org.bukkit.inventory.ItemStack; import dev.lone.vanillacustomizer.utils.Utils;
import org.apache.commons.io.FilenameUtils;
import org.bukkit.inventory.InventoryView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Customization public class Customization
{ {
public final boolean ignoreInventoriesEnabled;
public final boolean ignoreAnyCustomInventory;
public final List<String> ignoreInventoriesByTitle;
public List<IRule> rules = new ArrayList<>(); public List<IRule> rules = new ArrayList<>();
public List<IChange> changes = new ArrayList<>(); public List<IChange> changes = new ArrayList<>();
public Customization(boolean ignoreInventoriesEnabled, boolean ignoreAnyCustomInventory, List<String> ignoreInventoriesByTitle)
{
this.ignoreAnyCustomInventory = ignoreAnyCustomInventory;
this.ignoreInventoriesByTitle = ignoreInventoriesByTitle;
this.ignoreInventoriesEnabled = ignoreInventoriesEnabled;
}
public boolean isEmpty() public boolean isEmpty()
{ {
return rules.isEmpty() && changes.isEmpty(); return rules.isEmpty() && changes.isEmpty();
@@ -28,8 +41,24 @@ public class Customization
changes.add(change); changes.add(change);
} }
public boolean matchesAll(ChangeSession session) boolean matchesAll(ChangeSession session)
{ {
InventoryView openInventory = session.getPlayer().getOpenInventory();
if(ignoreInventoriesEnabled)
{
if(ignoreAnyCustomInventory)
{
if(Utils.isCustomInventory(openInventory))
return false;
}
for (String wildcard : ignoreInventoriesByTitle)
{
if (FilenameUtils.wildcardMatch(openInventory.getTitle(), wildcard))
return false;
}
}
for (IRule rule : rules) for (IRule rule : rules)
{ {
if(!rule.matches(session)) if(!rule.matches(session))

View File

@@ -6,8 +6,8 @@ import dev.lone.vanillacustomizer.ChangeSession;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import dev.lone.LoneLibs.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import dev.lone.LoneLibs.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;

View File

@@ -6,12 +6,12 @@ import dev.lone.vanillacustomizer.ChangeSession;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import dev.lone.LoneLibs.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import dev.lone.LoneLibs.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
@Deprecated //TODO @Deprecated //TODO implement this shit
public class AttributesRemove implements IChange public class AttributesRemove implements IChange
{ {
Multimap<Attribute, AttributeModifier> modifiers; Multimap<Attribute, AttributeModifier> modifiers;

View File

@@ -5,8 +5,12 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.ConfigFile; import dev.lone.vanillacustomizer.utils.ConfigFile;
import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LoreInsert implements IChange public class LoreInsert implements IChange
@@ -23,10 +27,44 @@ public class LoreInsert implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> loreNMS = nbt.getLoreCopy();
if (loreNMS == null)
{
loreNMS = new ArrayList<>();
for (String line : lines)
loreNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, line)));
}
else
{
// If the index is correctly inside the already existing lore range I can put the new lines there.
if (index < loreNMS.size())
{
int i = index;
for (String line : lines)
{
loreNMS.add(i, Utils.legacyToNMS(IChange.replacePlaceholders(session, line)));
i++;
}
}
else // If it's out of bounds I just append at the end.
{
for (String line : lines)
loreNMS.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line)));
}
}
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
if(!display.hasTag("Lore")) if (!display.hasTag("Lore"))
{ {
NBTList<String> lore = display.getStringList("Lore"); NBTList<String> lore = display.getStringList("Lore");
for (String line : lines) for (String line : lines)
@@ -36,7 +74,7 @@ public class LoreInsert implements IChange
{ {
NBTList<String> lore = display.getStringList("Lore"); NBTList<String> lore = display.getStringList("Lore");
// If the index is correctly inside the already existing lore range I can put the new lines there. // If the index is correctly inside the already existing lore range I can put the new lines there.
if(index < lore.size()) if (index < lore.size())
{ {
int i = index; int i = index;
for (String line : lines) for (String line : lines)
@@ -51,13 +89,31 @@ public class LoreInsert implements IChange
lore.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line))); lore.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line)));
} }
} }
session.saveNbt(); session.saveNbt();
} }
public static void putLine(ChangeSession session, int index, String line) public static void putLine(ChangeSession session, int index, String line)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> loreNMS = nbt.getLoreCopy();
if (loreNMS == null)
{
loreNMS = new ArrayList<>();
loreNMS.add(Utils.legacyToNMS(line));
}
else
{
loreNMS.add(index, Utils.legacyToNMS(line));
}
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
NBTList<String> lore = display.getStringList("Lore"); NBTList<String> lore = display.getStringList("Lore");

View File

@@ -3,8 +3,11 @@ package dev.lone.vanillacustomizer.customization.changes;
import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
import dev.lone.fastnbt_benchmark.libs.org.jetbrains.annotations.Nullable;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.vanillacustomizer.utils.Utilz; import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -16,21 +19,47 @@ public class LoreInsertJson implements IChange
public LoreInsertJson(List<String> linesJson, int index) public LoreInsertJson(List<String> linesJson, int index)
{ {
this.linesJson = Utilz.fixJsonFormatting(linesJson); this.linesJson = Utils.fixJsonFormatting(linesJson);
this.index = index; this.index = index;
} }
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> newLinesNMS = new ArrayList<>();
for (String lineJson : linesJson)
newLinesNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, lineJson)));
@Nullable List<Object> loreNMS = nbt.getLoreCopy();
if(loreNMS == null)
{
loreNMS = new ArrayList<>(newLinesNMS);
}
else
{
if (index < loreNMS.size())
loreNMS.addAll(index, newLinesNMS);
else
loreNMS.addAll(newLinesNMS);
}
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
List<String> newLinesJson = new ArrayList<>(); List<String> newLinesJson = new ArrayList<>();
for (String lineJson : linesJson) for (String lineJson : linesJson)
newLinesJson.add(IChange.replacePlaceholders(session, lineJson)); newLinesJson.add(IChange.replacePlaceholders(session, lineJson));
if(!display.hasTag("Lore")) if (!display.hasTag("Lore"))
{ {
NBTList<String> lore = display.getStringList("Lore"); NBTList<String> lore = display.getStringList("Lore");
lore.addAll(newLinesJson); lore.addAll(newLinesJson);
@@ -38,14 +67,10 @@ public class LoreInsertJson implements IChange
else else
{ {
NBTList<String> lore = display.getStringList("Lore"); NBTList<String> lore = display.getStringList("Lore");
if(index < lore.size()) if (index < lore.size())
{
lore.addAll(index, newLinesJson); lore.addAll(index, newLinesJson);
}
else else
{
lore.addAll(newLinesJson); lore.addAll(newLinesJson);
}
} }
session.saveNbt(); session.saveNbt();

View File

@@ -5,8 +5,13 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.ConfigFile; import dev.lone.vanillacustomizer.utils.ConfigFile;
import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import lonelibs.net.kyori.adventure.text.Component;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LoreSet implements IChange public class LoreSet implements IChange
@@ -21,7 +26,23 @@ public class LoreSet implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> loreNMS = new ArrayList<>();
for (String line : lines)
{
String json = Comp.legacyToJson(IChange.replacePlaceholders(session, line));
Component component = Utils.jsonToComponent(json);
Object nms = Comp.componentToNms(component);
loreNMS.add(nms);
}
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
display.removeKey("Lore"); display.removeKey("Lore");

View File

@@ -4,8 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.Utilz; import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -16,13 +17,24 @@ public class LoreSetJson implements IChange
public LoreSetJson(List<String> linesJson) public LoreSetJson(List<String> linesJson)
{ {
this.linesJson = Utilz.fixJsonFormatting(linesJson); this.linesJson = Utils.fixJsonFormatting(linesJson);
} }
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> loreNMS = new ArrayList<>();
for (String line : linesJson)
loreNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, line)));
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
display.removeKey("Lore"); display.removeKey("Lore");

View File

@@ -8,7 +8,7 @@ public class ProtectNbtData implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); NBTItem nbt = session.nbtLegacy();
nbt.removeKey("PublicBukkitValues"); nbt.removeKey("PublicBukkitValues");
nbt.removeKey("itemsadder"); nbt.removeKey("itemsadder");

View File

@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.ConfigFile; import dev.lone.vanillacustomizer.utils.ConfigFile;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public class Renamer implements IChange public class Renamer implements IChange
@@ -20,7 +22,15 @@ public class Renamer implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
nbt.setCustomName(Comp.legacyToJson(IChange.replacePlaceholders(session, name)));
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
display.setString("Name", Comp.legacyToJson(IChange.replacePlaceholders(session, name))); display.setString("Name", Comp.legacyToJson(IChange.replacePlaceholders(session, name)));

View File

@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.utils.Utilz; import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
public class RenamerJson implements IChange public class RenamerJson implements IChange
{ {
@@ -14,15 +16,24 @@ public class RenamerJson implements IChange
{ {
// This should validate if the json is valid and throw an exception if not. // This should validate if the json is valid and throw an exception if not.
// NOTE: test if it is actually the case. // NOTE: test if it is actually the case.
Comp.jsonToComponent(json); Utils.jsonToComponent(json);
this.json = Utilz.fixJsonFormatting(json); this.json = Utils.fixJsonFormatting(json);
} }
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
String json = IChange.replacePlaceholders(session, this.json);
nbt.setCustomName(json);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
display.setString("Name", IChange.replacePlaceholders(session, json)); display.setString("Name", IChange.replacePlaceholders(session, json));

View File

@@ -15,7 +15,7 @@ public class ReplaceCustomModelData implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); NBTItem nbt = session.nbtLegacy();
nbt.setInteger("CustomModelData", id); nbt.setInteger("CustomModelData", id);
session.saveNbt(); session.saveNbt();

View File

@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.ConfigFile; import dev.lone.vanillacustomizer.utils.ConfigFile;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
public class ReplaceWordDisplayName implements IChange public class ReplaceWordDisplayName implements IChange
{ {
@@ -27,7 +29,15 @@ public class ReplaceWordDisplayName implements IChange
String name = session.refreshMeta().getDisplayName().replace(from, to); String name = session.refreshMeta().getDisplayName().replace(from, to);
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
nbt.setCustomName(Comp.legacyToJson(name));
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
display.setString("Name", Comp.legacyToJson(name)); display.setString("Name", Comp.legacyToJson(name));

View File

@@ -5,10 +5,15 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.LoneLibs.chat.Comp; import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import dev.lone.vanillacustomizer.utils.ConfigFile; import dev.lone.vanillacustomizer.utils.ConfigFile;
import dev.lone.vanillacustomizer.utils.Utils;
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
import lonelibs.net.kyori.adventure.text.Component; import lonelibs.net.kyori.adventure.text.Component;
import lonelibs.net.kyori.adventure.text.TextReplacementConfig; import lonelibs.net.kyori.adventure.text.TextReplacementConfig;
import java.util.List;
public class ReplaceWordLore implements IChange public class ReplaceWordLore implements IChange
{ {
TextReplacementConfig textReplacement; TextReplacementConfig textReplacement;
@@ -27,7 +32,26 @@ public class ReplaceWordLore implements IChange
@Override @Override
public void apply(ChangeSession session) public void apply(ChangeSession session)
{ {
NBTItem nbt = session.nbt(); if(NMS.is_v1_1_20_5_or_greater)
{
NItem nbt = session.nbt();
List<Object> loreNMS = nbt.getLoreCopy();
if(loreNMS == null)
return;
for (int i = 0; i < loreNMS.size(); i++)
{
Object lineNMS = loreNMS.get(i);
Component component = Comp.nmsToComponent(lineNMS);
component = component.replaceText(textReplacement);
loreNMS.set(i, Comp.componentToNms(component));
}
nbt.setLore(loreNMS);
nbt.save();
return;
}
NBTItem nbt = session.nbtLegacy();
NBTCompound display = nbt.getOrCreateCompound("display"); NBTCompound display = nbt.getOrCreateCompound("display");
if(!display.hasTag("Lore")) if(!display.hasTag("Lore"))
return; return;
@@ -36,7 +60,7 @@ public class ReplaceWordLore implements IChange
for (int i = 0; i < lore.size(); i++) for (int i = 0; i < lore.size(); i++)
{ {
String lineJson = lore.get(i); String lineJson = lore.get(i);
Component component = Comp.jsonToComponent(lineJson); Component component = Utils.jsonToComponent(lineJson);
component = component.replaceText(textReplacement); component = component.replaceText(textReplacement);
lore.set(i, Comp.componentToJson(component)); lore.set(i, Comp.componentToJson(component));
} }

View File

@@ -28,7 +28,7 @@ public class RuleNbtMatcher implements IRule
{ {
nbtValueType = NBTType.valueOf(nbtTypeFixed); nbtValueType = NBTType.valueOf(nbtTypeFixed);
} }
catch(IllegalArgumentException exc) catch (IllegalArgumentException exc)
{ {
throw new IllegalArgumentException("Unknown nbt.type '" + nbtValueTypeStr + "' for nbt path '" + nbtPath + "'." + throw new IllegalArgumentException("Unknown nbt.type '" + nbtValueTypeStr + "' for nbt path '" + nbtPath + "'." +
ChatColor.GRAY + " Allowed: string, int, float, double, byte, short"); ChatColor.GRAY + " Allowed: string, int, float, double, byte, short");
@@ -49,6 +49,7 @@ public class RuleNbtMatcher implements IRule
break; break;
case NBTTagByte: case NBTTagByte:
nbtValue = Byte.parseByte(nbtValueStr); nbtValue = Byte.parseByte(nbtValueStr);
break;
case NBTTagShort: case NBTTagShort:
nbtValue = Short.parseShort(nbtValueStr); nbtValue = Short.parseShort(nbtValueStr);
break; break;
@@ -71,36 +72,40 @@ public class RuleNbtMatcher implements IRule
public boolean matches(ItemStack item) public boolean matches(ItemStack item)
{ {
NBTItem nbt = new NBTItem(item); NBTItem nbt = new NBTItem(item);
if (!nbt.hasTag(nbtPathSplit[0])) if (!nbt.hasTag(nbtPathSplit[0]))
return false; return false;
NBTCompound currentCompound = nbt.getCompound(nbtPathSplit[0]); NBTCompound currentCompound = nbt.getCompound(nbtPathSplit[0]);
for(int i=1; i<nbtPathSplit.length-1; i++) if(currentCompound == null)
return false;
for (int i = 1; i < nbtPathSplit.length - 1; i++)
{ {
assert currentCompound != null;
if (!currentCompound.hasTag(nbtPathSplit[i])) if (!currentCompound.hasTag(nbtPathSplit[i]))
return false; return false;
currentCompound = currentCompound.getCompound(nbtPathSplit[i]); currentCompound = currentCompound.getCompound(nbtPathSplit[i]);
} }
if (!currentCompound.hasTag(nbtPathSplit[nbtPathSplit.length-1]))
assert currentCompound != null;
if (!currentCompound.hasTag(nbtPathSplit[nbtPathSplit.length - 1]))
return false; return false;
NBTType nbtType = currentCompound.getType(nbtPathSplit[nbtPathSplit.length-1]); NBTType nbtType = currentCompound.getType(nbtPathSplit[nbtPathSplit.length - 1]);
if (nbtType != nbtValueType) if (nbtType != nbtValueType)
return false; return false;
if (nbtType == NBTType.NBTTagString) if (nbtType == NBTType.NBTTagString)
return (currentCompound.getString(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getString(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
else if (nbtType == NBTType.NBTTagInt) else if (nbtType == NBTType.NBTTagInt)
return (currentCompound.getInteger(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getInteger(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
else if (nbtType == NBTType.NBTTagDouble) else if (nbtType == NBTType.NBTTagDouble)
return (currentCompound.getDouble(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getDouble(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
else if (nbtType == NBTType.NBTTagFloat) else if (nbtType == NBTType.NBTTagFloat)
return (currentCompound.getFloat(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getFloat(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
else if (nbtType == NBTType.NBTTagByte) else if (nbtType == NBTType.NBTTagByte)
return (currentCompound.getByte(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getByte(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
else if (nbtType == NBTType.NBTTagShort) else if (nbtType == NBTType.NBTTagShort)
return (currentCompound.getShort(nbtPathSplit[nbtPathSplit.length-1]).equals(nbtValue)); return (currentCompound.getShort(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue));
return false; return false;
} }

View File

@@ -6,7 +6,7 @@ import org.apache.commons.io.IOCase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Deprecated @Deprecated // TODO: implement that shit
public class WildcardsMatcher implements ITextMatcher public class WildcardsMatcher implements ITextMatcher
{ {
// private List<String> wildcardStart; // private List<String> wildcardStart;

View File

@@ -14,6 +14,8 @@ public class RulePlaceable implements IRule
@Override @Override
public boolean matches(ItemStack item) public boolean matches(ItemStack item)
{ {
return item.getType().isBlock(); if(placeable)
return item.getType().isBlock();
return !item.getType().isBlock();
} }
} }

View File

@@ -1,7 +1,7 @@
package dev.lone.vanillacustomizer.customization.rules; package dev.lone.vanillacustomizer.customization.rules;
import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.ChangeSession;
import dev.lone.vanillacustomizer.utils.Utilz; import dev.lone.vanillacustomizer.utils.Utils;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@@ -27,14 +27,14 @@ public class RuleVanillaItemMatcher implements IRule
return true; return true;
// TODO: warning, items with no lore would still be considered vanilla while they might be custom. // TODO: warning, items with no lore would still be considered vanilla while they might be custom.
// might need to check NBT // Might need to check NBT.
if(meta.hasLore()) if(meta.hasLore())
{
return false; return false;
}
// TODO: check if it has PersistentDataContainer, for example.
String displayName = meta.getDisplayName(); String displayName = meta.getDisplayName();
displayName = Utilz.backColor(displayName); displayName = Utils.backColor(displayName);
// Check if italic, means that might have been renamed using anvil. // Check if italic, means that might have been renamed using anvil.
return !displayName.startsWith("&o"); return !displayName.startsWith("&o");
@@ -49,6 +49,8 @@ public class RuleVanillaItemMatcher implements IRule
@Override @Override
public boolean matches(ChangeSession session) public boolean matches(ChangeSession session)
{ {
return session.isVanilla; if(isVanilla)
return session.isVanilla;
return !session.isVanilla;
} }
} }

View File

@@ -0,0 +1,9 @@
package dev.lone.vanillacustomizer.exception;
public class InvalidCustomizationPropertyException extends IllegalArgumentException
{
public InvalidCustomizationPropertyException(String text)
{
super(text);
}
}

View File

@@ -1,8 +1,9 @@
package dev.lone.vanillacustomizer.nms; package dev.lone.vanillacustomizer.nms;
import dev.lone.LoneLibs.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import dev.lone.LoneLibs.nbt.nbtapi.utils.MinecraftVersion; import dev.lone.LoneLibs.nbt.nbtapi.utils.MinecraftVersion;
import dev.lone.vanillacustomizer.Main; import dev.lone.vanillacustomizer.Main;
import lonelibs.dev.lone.fastnbt.nms.Version;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@@ -10,19 +11,13 @@ import java.lang.reflect.InvocationTargetException;
/** /**
* Utility to initialize NMS wrappers and avoid Maven circular dependency problems. * Utility to initialize NMS wrappers and avoid Maven circular dependency problems.
*/ */
public class Nms public class NMS
{ {
public static boolean is_v18_2_or_greater; public static boolean is_v1_1_20_5_or_greater;
public static boolean is_v19_2_or_greater;
public static boolean is_v17_or_greater;
public static boolean is_v1_16_or_greater;
static static
{ {
is_v19_2_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_19_R1); is_v1_1_20_5_or_greater = Version.isAtLeast(Version.v1_20_5);
is_v18_2_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_18_R1);
is_v17_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1);
is_v1_16_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1);
} }
/** /**
@@ -36,9 +31,9 @@ public class Nms
*/ */
@Nullable @Nullable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T findImplementation(Class<T> implClazz, Object nmsHolder, boolean ignoreError) public static <T> T findImplementation(@SuppressWarnings("unused") Class<T> implClazz, Object nmsHolder, boolean ignoreError)
{ {
String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; String nmsVersion = Version.get().name();
try try
{ {

View File

@@ -1,6 +1,6 @@
package dev.lone.vanillacustomizer.nms.items; package dev.lone.vanillacustomizer.nms.items;
import dev.lone.vanillacustomizer.nms.Nms; import dev.lone.vanillacustomizer.nms.NMS;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.CookingRecipe; import org.bukkit.inventory.CookingRecipe;
@@ -17,7 +17,7 @@ public class ItemsNms
ItemsNms() ItemsNms()
{ {
nms = Nms.findImplementation(IItemsNms.class, this, false); nms = NMS.findImplementation(IItemsNms.class, this, false);
} }
public static ItemsNms inst() public static ItemsNms inst()

View File

@@ -2,6 +2,7 @@ package dev.lone.vanillacustomizer.nms.items;
import org.bukkit.Color; import org.bukkit.Color;
@SuppressWarnings("unused")
public enum Rarity public enum Rarity
{ {
COMMON(Color.WHITE), COMMON(Color.WHITE),

View File

@@ -1,8 +1,8 @@
package dev.lone.vanillacustomizer.utils; package dev.lone.vanillacustomizer.utils;
import dev.lone.LoneLibs.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import dev.lone.vanillacustomizer.Main; import dev.lone.vanillacustomizer.Main;
import dev.lone.vanillacustomizer.nms.Nms; import dev.lone.vanillacustomizer.nms.NMS;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -15,7 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import dev.lone.LoneLibs.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
/** /**
* 2020-01-08 LoneDev * 2020-01-08 LoneDev
*/ */
@SuppressWarnings("unused")
public class ConfigFile public class ConfigFile
{ {
private static final Pattern hexPattern = Pattern.compile("%#([A-Fa-f0-9]){6}%"); private static final Pattern hexPattern = Pattern.compile("%#([A-Fa-f0-9]){6}%");
@@ -220,17 +221,14 @@ public class ConfigFile
private static String convertColor0(String message) private static String convertColor0(String message)
{ {
if (Nms.is_v1_16_or_greater) Matcher matcher = hexPattern.matcher(message);
while (matcher.find())
{ {
Matcher matcher = hexPattern.matcher(message); final net.md_5.bungee.api.ChatColor hexColor = net.md_5.bungee.api.ChatColor.of(matcher.group().substring(1, matcher.group().length() - 1));
while (matcher.find()) final String before = message.substring(0, matcher.start());
{ final String after = message.substring(matcher.end());
final net.md_5.bungee.api.ChatColor hexColor = net.md_5.bungee.api.ChatColor.of(matcher.group().substring(1, matcher.group().length() - 1)); message = before + hexColor + after;
final String before = message.substring(0, matcher.start()); matcher = hexPattern.matcher(message);
final String after = message.substring(matcher.end());
message = before + hexColor + after;
matcher = hexPattern.matcher(message);
}
} }
return message.replace("&", "\u00A7"); return message.replace("&", "\u00A7");
} }

View File

@@ -1,6 +1,6 @@
package dev.lone.vanillacustomizer.utils; package dev.lone.vanillacustomizer.utils;
import dev.lone.LoneLibs.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class SmallCaps public class SmallCaps
{ {

View File

@@ -0,0 +1,131 @@
package dev.lone.vanillacustomizer.utils;
import com.google.gson.JsonSyntaxException;
import dev.lone.LoneLibs.chat.Comp;
import dev.lone.vanillacustomizer.nms.NMS;
import lonelibs.net.kyori.adventure.text.Component;
import lonelibs.net.kyori.adventure.text.format.TextColor;
import lonelibs.net.kyori.adventure.text.format.TextDecoration;
import lonelibs.org.jetbrains.annotations.NotNull;
import org.bukkit.attribute.Attribute;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryView;
import java.util.*;
import java.util.regex.Pattern;
public class Utils
{
private static final Pattern PATTERN_IS_NUMERIC = Pattern.compile("-?\\d+(\\.\\d+)?");
public static String backColor(String name)
{
return name.replace("\u00A7", "&");
}
/**
* @param strNum check if it is numeric
*/
public static boolean isNumeric(String strNum)
{
if (strNum == null)
return false;
return PATTERN_IS_NUMERIC.matcher(strNum).matches();
}
public static int parseInt(String number, int defaultValue)
{
try
{
return Integer.parseInt(number);
}
catch (Throwable ignored)
{
}
return defaultValue;
}
// https://minecraft.wiki/w/Attribute
public static Attribute strToAttributeType(String attributeModifier)
{
attributeModifier = attributeModifier.replace("minecraft:", "");
return switch (attributeModifier)
{
case "generic.max_health" -> Attribute.GENERIC_MAX_HEALTH;
case "generic.follow_range" -> Attribute.GENERIC_FOLLOW_RANGE;
case "generic.knockback_resistance" -> Attribute.GENERIC_KNOCKBACK_RESISTANCE;
case "generic.movement_speed" -> Attribute.GENERIC_MOVEMENT_SPEED;
case "generic.flying_speed" -> Attribute.GENERIC_FLYING_SPEED;
case "generic.attack_damage" -> Attribute.GENERIC_ATTACK_DAMAGE;
case "generic.attack_knockback" -> // 1.16+
Attribute.GENERIC_ATTACK_KNOCKBACK;
case "generic.attack_speed" -> Attribute.GENERIC_ATTACK_SPEED;
case "generic.armor" -> Attribute.GENERIC_ARMOR;
case "generic.armor_toughness" -> Attribute.GENERIC_ARMOR_TOUGHNESS;
case "generic.luck" -> Attribute.GENERIC_LUCK;
case "zombie.spawn_reinforcements" -> Attribute.ZOMBIE_SPAWN_REINFORCEMENTS;
case "horse.jump_strength" ->
{
if (NMS.is_v1_1_20_5_or_greater)
yield Attribute.valueOf("HORSE_JUMP_STRENGTH");
yield Attribute.GENERIC_JUMP_STRENGTH;
}
default -> null;
};
}
public static EquipmentSlot strToVanillaEquipmentSlot(String str)
{
return switch (str.toLowerCase())
{
case "head" -> EquipmentSlot.HEAD;
case "chest" -> EquipmentSlot.CHEST;
case "legs" -> EquipmentSlot.LEGS;
case "feet" -> EquipmentSlot.FEET;
case "mainhand" -> EquipmentSlot.HAND;
case "offhand" -> EquipmentSlot.OFF_HAND;
default -> null;
};
}
public static List<String> fixJsonFormatting(List<String> linesJson)
{
for (int i = 0, linesJsonSize = linesJson.size(); i < linesJsonSize; i++)
{
String jsonLine = linesJson.get(i);
linesJson.set(i, fixJsonFormatting(jsonLine));
}
return linesJson;
}
public static String fixJsonFormatting(String jsonString)
{
Component component = Utils.jsonToComponent(jsonString);
component = component.colorIfAbsent(TextColor.color(255, 255, 255));
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
return Comp.componentToJson(component);
}
public static Object jsonToNMS(String json)
{
return Comp.componentToNms(Utils.jsonToComponent(json));
}
public static Object legacyToNMS(String text)
{
return Comp.componentToNms(jsonToComponent(Comp.legacyToJson(text)));
}
public static @NotNull Component jsonToComponent(String json) throws JsonSyntaxException
{
if ((json.startsWith("{") && json.endsWith("}") || (json.startsWith("[") && json.endsWith("]"))))
return Comp.GSON_SERIALIZER.deserialize(json);
return Component.text(json).style(Comp.WHITE_NORMAL_TEXT_STYLE);
}
public static boolean isCustomInventory(InventoryView openInventory)
{
return openInventory.getTopInventory().getClass().toString().endsWith("CraftInventoryCustom");
}
}

View File

@@ -1,599 +0,0 @@
package dev.lone.vanillacustomizer.utils;
import dev.lone.LoneLibs.chat.Comp;
import lonelibs.net.kyori.adventure.text.Component;
import lonelibs.net.kyori.adventure.text.format.TextColor;
import lonelibs.net.kyori.adventure.text.format.TextDecoration;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.reflect.FieldUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.CharacterIterator;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.text.StringCharacterIterator;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class Utilz
{
public static Random random = new Random();
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("##.00");
private static final Pattern PATTERN_HEX = Pattern.compile("%#([A-Fa-f0-9]){6}%");
private static final Pattern PATTERN_IS_NUMERIC = Pattern.compile("-?\\d+(\\.\\d+)?");
public static void removeEnchantments(ItemStack item)
{
item.getEnchantments().keySet().forEach(item::removeEnchantment);
}
public static String addSpace(String s)
{
return s.replace("-", " ");
}
public static float getRandom(String level)
{
if (level.contains("-"))
{
String[] spl = level.split("-");
return round(randomNumber(Float.parseFloat(spl[0]), Float.parseFloat(spl[1])), 2);
}
else return Integer.parseInt(level);
}
public static int getRandomInt(String level)
{
if (level.contains("-"))
{
String[] spl = level.split("-");
return getRandomInt(Integer.parseInt(spl[0]), Integer.parseInt(spl[1]));
}
else return Integer.parseInt(level);
}
public static float round(float d, int decimalPlace)
{
BigDecimal bd = new BigDecimal(Float.toString(d));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
public static String round(double value, int places, boolean showZeroes)
{
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
String result = bd.doubleValue() + "";
if (!showZeroes)
result = result
.replace(".00", "")
.replace(".0", "");
return result;
}
public static float randomNumber(float f, float g)
{
return random.nextFloat() * (g - f) + f;
}
/**
* Returns a 0 to 1 random double.
*
* @return A random double from 0 to 1.
*/
public static double randomNumber()
{
return random.nextDouble();
}
/**
* Supports negative min
*/
public static int getRandomInt(int min, int max)
{
if (max == min)
return max;
return random.nextInt((max - min) + 1) + min;
}
/**
* Supports negative min
*/
public static int getRandomInt(Random random, int min, int max)
{
if (max == min)
return max;
return random.nextInt((max - min) + 1) + min;
}
public static boolean getSuccess(int percent)
{
int i = getRandomInt(1, 100);
return i <= percent;
}
public static boolean hasPermmision(Player p, String perm)
{
if (p.hasPermission(perm)) return true;
return p.isOp();
}
public static String backColor(String name)
{
return name.replace("\u00A7", "&");
}
public static boolean isColored(String str)
{
return str.contains("\u00A7([0-fk-or])") || str.contains("&([0-fk-or])");
}
/**
* @param strNum check if it is numeric
*/
public static boolean isNumeric(String strNum)
{
if (strNum == null)
return false;
return PATTERN_IS_NUMERIC.matcher(strNum).matches();
}
private static java.awt.Color hex2Rgb(String colorStr)
{
try
{
return new java.awt.Color(
Integer.valueOf(colorStr.substring(1, 3), 16),
Integer.valueOf(colorStr.substring(3, 5), 16),
Integer.valueOf(colorStr.substring(5, 7), 16)
);
}
catch (Throwable e)
{
e.printStackTrace();
}
return null;
}
public static Color hexToBukkitColor(String colorStr)
{
if (colorStr == null)
return null;
//fix java.lang.NumberFormatException: For input string: ".0"
if (colorStr.endsWith(".0"))
colorStr = colorStr.replace(".0", "");
colorStr = colorStr.replace(".", "");
//fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7
while (colorStr.length() < 7)
colorStr = colorStr + "0";
if (!colorStr.startsWith("#"))
colorStr = "#" + colorStr;
java.awt.Color javaColor = hex2Rgb(colorStr);
return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue());
}
public static String colorToHexString(int rgb)
{
java.awt.Color tmp = new java.awt.Color(rgb);
return colorToHexString(tmp.getRed(), tmp.getGreen(), tmp.getBlue());
}
public static String colorToHexString(Color color, boolean hashtagPrefix)
{
java.awt.Color tmp = new java.awt.Color(color.asRGB());
return colorToHexString(tmp.getRed(), tmp.getGreen(), tmp.getBlue(), hashtagPrefix);
}
public static String colorToHexString(int r, int g, int b)
{
return colorToHexString(r, g, b, true);
}
public static String colorToHexString(int r, int g, int b, boolean hashtagPrefix)
{
if (hashtagPrefix)
return String.format("#%02x%02x%02x", r, g, b);
return String.format("%02x%02x%02x", r, g, b);
}
public static Color bukkitColor(int rgb)
{
java.awt.Color tmp = new java.awt.Color(rgb);
return Color.fromRGB(tmp.getRed(), tmp.getGreen(), tmp.getBlue());
}
public static int ceilDivision(float a, float b)
{
return (int) Math.ceil(a / b);
}
public static int parseInt(String number, int defaultValue)
{
try
{
return Integer.parseInt(number);
}
catch (Throwable ignored){}
return defaultValue;
}
public static float parseFloat(String number, float defaultValue)
{
try
{
return Float.parseFloat(number);
}
catch (Throwable ignored){}
return defaultValue;
}
public static Color bukkitColorFromString(String potionColorStr)
{
try
{
return (Color) FieldUtils.readStaticField(Color.class, potionColorStr);
}
catch (Exception e)
{
try
{
if (!Utilz.isNumeric(potionColorStr))
{
if (potionColorStr == null)
return null;
//fix java.lang.NumberFormatException: For input string: ".0"
if (potionColorStr.endsWith(".0"))
potionColorStr = potionColorStr.replace(".0", "");
potionColorStr = potionColorStr.replace(".", "");
//fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7
while (potionColorStr.length() < 7)
potionColorStr = potionColorStr + "0";
if (!potionColorStr.startsWith("#"))
potionColorStr = "#" + potionColorStr;
java.awt.Color javaColor = hex2Rgb(potionColorStr);
return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue());
}
else
{
Color.fromBGR(Integer.parseInt(potionColorStr));
}
}
catch (Throwable ignored)
{
}
}
return null;
}
public static int bukkitColorFromString_integer(String potionColorStr)
{
try
{
return ((Color) FieldUtils.readStaticField(Color.class, potionColorStr)).asRGB();
}
catch (Exception e)
{
try
{
if (!Utilz.isNumeric(potionColorStr))
{
if (potionColorStr == null)
return -1;
//fix java.lang.NumberFormatException: For input string: ".0"
if (potionColorStr.endsWith(".0"))
potionColorStr = potionColorStr.replace(".0", "");
potionColorStr = potionColorStr.replace(".", "");
//fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7
while (potionColorStr.length() < 7)
potionColorStr = potionColorStr + "0";
if (!potionColorStr.startsWith("#"))
potionColorStr = "#" + potionColorStr;
java.awt.Color javaColor = hex2Rgb(potionColorStr);
return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue()).asRGB();
}
else
{
return Integer.parseInt(potionColorStr);
}
}
catch (Throwable ignored){}
}
return -1;
}
public static boolean isBetween(int number, int min, int max, boolean equals)
{
if (equals)
return number >= min && number <= max;
return number > min && number < max;
}
public static boolean isBetween(int number, int min, int max)
{
return isBetween(number, min, max, true);
}
public static String getDateNowFormatted()
{
return getDateFormatted(new Date());
}
public static String getDateFormatted(Date date)
{
return new SimpleDateFormat("yyyy-MM-dd_HH-mm").format(date);
}
public static void printFunctionCaller()
{
try
{
StackTraceElement[] stackTrace = new Throwable().fillInStackTrace().getStackTrace();
StringBuilder a = new StringBuilder();
for (int i = 1; i < stackTrace.length; i++)
a.append(stackTrace[i].getMethodName() + ":" + stackTrace[i].getLineNumber()).append("->");
System.out.println(a.toString());
}
catch (Throwable ignored)
{
}
}
public static void showBook(Player player, String json)
{
ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
Bukkit.getUnsafe().modifyItemStack(book, json);
player.openBook(book);
}
public static int rgb(int r, int g, int b)
{
return new java.awt.Color(r, g, b, 255).getRGB();
}
public static boolean mkdirs(String path, boolean printErrors)
{
File file = new File(path);
if (file.exists())
return true;
try
{
Files.createDirectories(file.toPath());
}
catch (Throwable e)
{
if (printErrors)
e.printStackTrace();
return false;
}
return true;
}
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value)
{
return map.entrySet()
.stream()
.filter(entry -> Objects.equals(entry.getValue(), value))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}
/** See: {@link Utilz#partialFilePath(String)}. */
public static String partialFilePath(File file)
{
return partialFilePath(file.getAbsolutePath());
}
/**
* Input:
* "C:/Progetti/Minecraft/TestServer/1.19/plugins/ItemsAdder/contents/_iainternal/resourcepack/assets/_iainternal/textures/icons/icon_next_orange.png"
* "C:/Progetti/Minecraft/TestServer/blank_template/1.19.4/plugins/ModelEngine/resource pack/contents/prova/123/asd"
* Output:
* "contents/_iainternal/resourcepack/assets/_iainternal/textures/icons/icon_next_orange.png"
* "resource pack/contents/prova/123/asd"
*/
public static String partialFilePath(String fileAbsolutePath)
{
if (fileAbsolutePath == null)
return null;
String finalPath = fileAbsolutePath.replace("\\", "/");
int indexOfPlugins = finalPath.indexOf("plugins/");
if(indexOfPlugins != -1)
finalPath = finalPath.substring(indexOfPlugins);
// Remove the plugins/XXX/ text
int indexOfSlash = finalPath.indexOf("/");
if(indexOfSlash != -1)
finalPath = finalPath.substring(indexOfSlash + 1);
indexOfSlash = finalPath.indexOf("/");
if(indexOfSlash != -1)
finalPath = finalPath.substring(indexOfSlash + 1);
return finalPath;
}
public static int getFilesCount(File dir)
{
String[] list = dir.list();
if (list == null)
return 0;
return list.length;
}
public static String getPathRelativeToServerRoot(File file)
{
String serveRootPath = Bukkit.getServer().getWorldContainer().getAbsolutePath();
if (serveRootPath.endsWith("."))
serveRootPath = serveRootPath.substring(0, serveRootPath.length() - 2);
File serverRootDir = new File(serveRootPath).getParentFile();
return file.getAbsolutePath().replace(serverRootDir.getAbsolutePath(), "");
}
public static Path path(String path)
{
return new File(path).toPath();
}
/**
* Very important, zip files must use / not \\ or Minecraft won't recognize files..
*/
public static String sanitizePath(String str)
{
str = str.replace("\\", "/");
if (str.startsWith("/"))
str = str.substring(1);
return str;
}
public static String sanitizedPath(File file)
{
return sanitizePath(file.getAbsolutePath());
}
public static String removeStartsWith(String str, String starsWith)
{
if (str.startsWith(starsWith))
return str.substring(starsWith.length());
return str;
}
public static String removeEndsWith(String str, String endsWith)
{
return str.replaceFirst(endsWith + "$", "");
}
public static String getLastNormalizedPathEntry(String str)
{
return str.substring(str.lastIndexOf('/') + 1);
}
public static String cloneString(String str)
{
return new String(str.getBytes(StandardCharsets.UTF_8));
}
public static <T> T[] copy(T[] matrix)
{
return Arrays.copyOf(matrix, matrix.length);
}
public static String fileExtension(File file)
{
return FilenameUtils.getExtension(file.getAbsolutePath());
}
public static String fileName(File file, boolean extension)
{
if(extension)
return file.getName();
return FilenameUtils.getBaseName(file.getAbsolutePath());
}
public static String humanReadableByteCountSI(long bytes)
{
if (-1000 < bytes && bytes < 1000)
{
return bytes + " B";
}
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
while (bytes <= -999_950 || bytes >= 999_950)
{
bytes /= 1000;
ci.next();
}
return String.format("%.1f %cB", bytes / 1000.0, ci.current());
}
public static int minMax(int value, int min, int max)
{
if(value < min)
return min;
return Math.min(value, max);
}
public static String substringBefore(String string, String before)
{
return string.substring(string.indexOf(before));
}
public static Attribute strToAttributeType(String attributeModifier)
{
attributeModifier = attributeModifier.replace("minecraft:", "");
return switch (attributeModifier)
{
case "generic.max_health" -> Attribute.GENERIC_MAX_HEALTH;
case "generic.follow_range" -> Attribute.GENERIC_FOLLOW_RANGE;
case "generic.knockback_resistance" -> Attribute.GENERIC_KNOCKBACK_RESISTANCE;
case "generic.movement_speed" -> Attribute.GENERIC_MOVEMENT_SPEED;
case "generic.flying_speed" -> Attribute.GENERIC_FLYING_SPEED;
case "generic.attack_damage" -> Attribute.GENERIC_ATTACK_DAMAGE;
case "generic.attack_knockback" -> // 1.16+
Attribute.GENERIC_ATTACK_KNOCKBACK;
case "generic.attack_speed" -> Attribute.GENERIC_ATTACK_SPEED;
case "generic.armor" -> Attribute.GENERIC_ARMOR;
case "generic.armor_toughness" -> Attribute.GENERIC_ARMOR_TOUGHNESS;
case "generic.luck" -> Attribute.GENERIC_LUCK;
case "zombie.spawn_reinforcements" -> Attribute.ZOMBIE_SPAWN_REINFORCEMENTS;
case "horse.jump_strength" -> Attribute.HORSE_JUMP_STRENGTH;
default -> null;
};
}
public static EquipmentSlot strToVanillaEquipmentSlot(String str)
{
return switch (str.toLowerCase())
{
case "head" -> EquipmentSlot.HEAD;
case "chest" -> EquipmentSlot.CHEST;
case "legs" -> EquipmentSlot.LEGS;
case "feet" -> EquipmentSlot.FEET;
case "mainhand" -> EquipmentSlot.HAND;
case "offhand" -> EquipmentSlot.OFF_HAND;
default -> null;
};
}
public static List<String> fixJsonFormatting(List<String> linesJson)
{
for (int i = 0, linesJsonSize = linesJson.size(); i < linesJsonSize; i++)
{
String jsonLine = linesJson.get(i);
linesJson.set(i, fixJsonFormatting(jsonLine));
}
return linesJson;
}
public static String fixJsonFormatting(String jsonString)
{
Component component = Comp.jsonToComponent(jsonString);
component = component.colorIfAbsent(TextColor.color(255, 255, 255));
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
return Comp.componentToJson(component);
}
}

View File

@@ -1,5 +1,5 @@
name: VanillaCustomizer name: VanillaCustomizer
version: 0.2 version: 0.3
main: dev.lone.vanillacustomizer.Main main: dev.lone.vanillacustomizer.Main
api-version: 1.13 api-version: 1.13
commands: commands:

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -46,23 +46,21 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>exec-maven-plugin</artifactId> <artifactId>maven-antrun-plugin</artifactId>
<version>1.2.1</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<id>CopyFile</id>
<phase>package</phase> <phase>package</phase>
<configuration> <configuration>
<executable>cmd</executable> <target>
<workingDirectory>${project.parent.basedir}</workingDirectory> <!-- Copy JAR to multiple directories -->
<arguments> <copy file="${basedir}/../output/${project.parent.artifactId}.jar" todir="C:/Progetti/Minecraft/TestServer/1.20.6/plugins/"/>
<argument>/C</argument> <copy file="${basedir}/../output/${project.parent.artifactId}.jar" todir="C:/Progetti/Minecraft/TestServer/1.21.1/plugins/"/>
<argument>.mvn-exec\CopyFile.bat</argument> </target>
</arguments>
</configuration> </configuration>
<goals> <goals>
<goal>exec</goal> <goal>run</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
@@ -84,38 +82,48 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_21_1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_20_6</artifactId>
<version>1.0</version>
</dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_20_R3</artifactId> <artifactId>VanillaCustomizer-nms-v1_20_R3</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_20_R2</artifactId> <artifactId>VanillaCustomizer-nms-v1_20_R2</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_20_R1</artifactId> <artifactId>VanillaCustomizer-nms-v1_20_R1</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_19_R3</artifactId> <artifactId>VanillaCustomizer-nms-v1_19_R3</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_18_R2</artifactId> <artifactId>VanillaCustomizer-nms-v1_18_R2</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-nms-v1_17_R1</artifactId> <artifactId>VanillaCustomizer-nms-v1_17_R1</artifactId>
<version>VERSION</version> <version>1.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_17_R1 implements IItemsNms public class v1_17_R1 implements IItemsNms
{ {
@Override @Override

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_18_R2 implements IItemsNms public class v1_18_R2 implements IItemsNms
{ {
@Override @Override

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R3.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_19_R3.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_19_R3 implements IItemsNms public class v1_19_R3 implements IItemsNms
{ {
@Override @Override

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>VanillaCustomizer-nms-v1_20_6</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>ca.bkaw</groupId>
<artifactId>paper-nms-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>remap</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ca.bkaw</groupId>
<artifactId>paper-nms</artifactId>
<version>1.20.6-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,48 @@
package dev.lone.vanillacustomizer.nms.items.impl;
import dev.lone.vanillacustomizer.nms.items.IItemsNms;
import dev.lone.vanillacustomizer.nms.items.Rarity;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.level.block.Block;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_20_6 implements IItemsNms
{
@Override
public Rarity getRarity(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem);
return Rarity.values()[item.getRarity().ordinal()];
}
@Override
public float getDestroySpeed(ItemStack bukkitItem)
{
Block block = CraftMagicNumbers.getBlock(bukkitItem.getType());
return block.defaultBlockState().destroySpeed;
}
@Override
public int getNutrition(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
FoodProperties foodProperties = itemStack.get(DataComponents.FOOD);
if(foodProperties != null)
return foodProperties.nutrition();
return 0;
}
@Override
public float getSaturation(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
FoodProperties foodProperties = itemStack.get(DataComponents.FOOD);
if(foodProperties != null)
return foodProperties.saturation();
return 0;
}
}

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_20_R1 implements IItemsNms public class v1_20_R1 implements IItemsNms
{ {
@Override @Override

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_20_R2 implements IItemsNms public class v1_20_R2 implements IItemsNms
{ {
@Override @Override

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<version>VERSION</version> <version>1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId> <artifactId>VanillaCustomizer-core</artifactId>
<version>VERSION</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_20_R3.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_20_R3 implements IItemsNms public class v1_20_R3 implements IItemsNms
{ {
@Override @Override

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>VanillaCustomizer</artifactId>
<groupId>dev.lone</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>VanillaCustomizer-nms-v1_21_1</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>ca.bkaw</groupId>
<artifactId>paper-nms-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>remap</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ca.bkaw</groupId>
<artifactId>paper-nms</artifactId>
<version>1.21.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer-core</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,48 @@
package dev.lone.vanillacustomizer.nms.items.impl;
import dev.lone.vanillacustomizer.nms.items.IItemsNms;
import dev.lone.vanillacustomizer.nms.items.Rarity;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.level.block.Block;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("unused")
public class v1_21_1 implements IItemsNms
{
@Override
public Rarity getRarity(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem);
return Rarity.values()[item.getRarity().ordinal()];
}
@Override
public float getDestroySpeed(ItemStack bukkitItem)
{
Block block = CraftMagicNumbers.getBlock(bukkitItem.getType());
return block.defaultBlockState().destroySpeed;
}
@Override
public int getNutrition(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
FoodProperties foodProperties = itemStack.get(DataComponents.FOOD);
if(foodProperties != null)
return foodProperties.nutrition();
return 0;
}
@Override
public float getSaturation(ItemStack bukkitItem)
{
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
FoodProperties foodProperties = itemStack.get(DataComponents.FOOD);
if(foodProperties != null)
return foodProperties.saturation();
return 0;
}
}

View File

@@ -6,7 +6,7 @@
<groupId>dev.lone</groupId> <groupId>dev.lone</groupId>
<artifactId>VanillaCustomizer</artifactId> <artifactId>VanillaCustomizer</artifactId>
<version>VERSION</version> <version>1.0</version>
<name>VanillaCustomizer</name> <name>VanillaCustomizer</name>
<packaging>pom</packaging> <packaging>pom</packaging>
@@ -22,6 +22,8 @@
<modules> <modules>
<module>VanillaCustomizer-core</module> <module>VanillaCustomizer-core</module>
<module>VanillaCustomizer-jar</module> <module>VanillaCustomizer-jar</module>
<module>VanillaCustomizer-nms-v1_21_1</module>
<module>VanillaCustomizer-nms-v1_20_6</module>
<module>VanillaCustomizer-nms-v1_20_R3</module> <module>VanillaCustomizer-nms-v1_20_R3</module>
<module>VanillaCustomizer-nms-v1_20_R2</module> <module>VanillaCustomizer-nms-v1_20_R2</module>
<module>VanillaCustomizer-nms-v1_20_R1</module> <module>VanillaCustomizer-nms-v1_20_R1</module>