Various changes
nbt matcher byte value not working https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/12 1.21.1 support https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/11 1.20.6 support https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/10 `is_vanilla_item: false` not working correctly https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/9 Newest LoneLibs support https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/8 Ignoring inventory rule is ignored https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/7 ERROR -> /vanillacustomizer small https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/5 Invalid NBT match rule https://github.com/PluginBugs/Issues-VanillaCustomizer/issues/4
BIN
.assets/banner.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
.assets/banner_big.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
.assets/icon.png
Normal file
|
After Width: | Height: | Size: 878 B |
BIN
.assets/product_page.png
Normal file
|
After Width: | Height: | Size: 480 KiB |
BIN
.assets/screenshots/screen1.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
.assets/screenshots/screen2.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
.assets/screenshots/screen3.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
.assets/screenshots/screen4.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
2
.gitattributes
vendored
@@ -1,2 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
8
.gitignore
vendored
@@ -111,9 +111,9 @@ buildNumber.properties
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
# My stuff
|
||||
/.cache/
|
||||
/output/
|
||||
/.paper-nms/
|
||||
/custom_mapping.txt
|
||||
/.assets/
|
||||
target
|
||||
/output/
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -5,13 +5,14 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
|
||||
<repositories>
|
||||
<!-- This adds the Spigot Maven repository to the build -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
@@ -25,34 +26,71 @@
|
||||
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>matteodev</id>
|
||||
<url>https://www.matteodev.it/spigot/public/maven/</url>
|
||||
<id>papermc</id>
|
||||
<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>
|
||||
</repositories>
|
||||
|
||||
|
||||
<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>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<groupId>dev.lone.LoneLibs</groupId>
|
||||
<artifactId>LoneLibs</artifactId>
|
||||
<version>1.0.50</version>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${jars_libs_folder}/LoneLibs.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>libs</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>provided</scope>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${jars_libs_folder}/ProtocolLib.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>24.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,8 +1,11 @@
|
||||
package dev.lone.vanillacustomizer;
|
||||
|
||||
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.nms.NMS;
|
||||
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@@ -10,20 +13,23 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
public class ChangeSession
|
||||
{
|
||||
public final ItemStack item;
|
||||
private final Player player;
|
||||
public final ItemStack originalItem;
|
||||
|
||||
public ItemMeta meta;
|
||||
|
||||
public NBTItem nbt;
|
||||
public NBTItem nbtLegacy;
|
||||
public NItem nbt;
|
||||
|
||||
public final boolean isVanilla;
|
||||
|
||||
@Nullable
|
||||
private Boolean hasChanged_cached;
|
||||
|
||||
public ChangeSession(ItemStack item, boolean trackChanges)
|
||||
public ChangeSession(ItemStack item, Player player, boolean trackChanges)
|
||||
{
|
||||
this.item = item;
|
||||
this.player = player;
|
||||
if(trackChanges)
|
||||
this.originalItem = item.clone();
|
||||
else
|
||||
@@ -32,6 +38,11 @@ public class ChangeSession
|
||||
isVanilla = RuleVanillaItemMatcher.satisfy(item);
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
public ItemMeta refreshMeta()
|
||||
{
|
||||
// Meta always needs to be refreshed as Spigot caches it!
|
||||
@@ -39,16 +50,26 @@ public class ChangeSession
|
||||
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)
|
||||
return nbt;
|
||||
refreshNbt();
|
||||
refreshNBT();
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@@ -59,12 +80,14 @@ public class ChangeSession
|
||||
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.
|
||||
if(nbt != null)
|
||||
nbt.save();
|
||||
}
|
||||
|
||||
public void applyMeta()
|
||||
{
|
||||
this.item.setItemMeta(this.meta);
|
||||
refreshNbt();
|
||||
refreshNBT();
|
||||
}
|
||||
|
||||
public boolean hasChanged()
|
||||
@@ -80,7 +103,7 @@ public class ChangeSession
|
||||
|
||||
public void refreshAll()
|
||||
{
|
||||
refreshNbt();
|
||||
refreshNBT();
|
||||
refreshMeta();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package dev.lone.vanillacustomizer;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
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.commands.registered.MainCommand;
|
||||
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);
|
||||
|
||||
ConfigurationSection cosmeticsSection = config.getConfigurationSection("customizations");
|
||||
if (cosmeticsSection == null) // File has no rules
|
||||
boolean ignoreInventoriesEnabled = config.getBoolean("settings.ignore_inventories.enabled");
|
||||
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;
|
||||
|
||||
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);
|
||||
assert section != null;
|
||||
|
||||
@@ -169,7 +178,7 @@ public class Customizations
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
if(ex instanceof InvalidCustomizationPropertyExtension)
|
||||
if(ex instanceof InvalidCustomizationPropertyException)
|
||||
{
|
||||
Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath());
|
||||
Main.msg.error(ex.getMessage());
|
||||
@@ -282,10 +291,10 @@ public class Customizations
|
||||
}
|
||||
else if (tmp.length == 2)
|
||||
{
|
||||
if (Utilz.isNumeric(tmp[1]))
|
||||
if (Utils.isNumeric(tmp[1]))
|
||||
{
|
||||
enchant = Enchantment.getByName(tmp[0]);
|
||||
enchantLevel = Utilz.parseInt(tmp[1], 1);
|
||||
enchantLevel = Utils.parseInt(tmp[1], 1);
|
||||
|
||||
if (enchant == null)
|
||||
enchant = Enchantment.getByKey(NamespacedKey.minecraft(tmp[0]));
|
||||
@@ -298,7 +307,7 @@ public class Customizations
|
||||
else if (tmp.length == 3)
|
||||
{
|
||||
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);
|
||||
@@ -324,7 +333,7 @@ public class Customizations
|
||||
}
|
||||
else if (tmp.length == 2)
|
||||
{
|
||||
if (Utilz.isNumeric(tmp[1]))
|
||||
if (Utils.isNumeric(tmp[1]))
|
||||
{
|
||||
enchant = Enchantment.getByName(tmp[0]);
|
||||
if (enchant == null)
|
||||
@@ -360,11 +369,11 @@ public class Customizations
|
||||
throwInvalidConfig();
|
||||
|
||||
@Nullable String attributeStr = getStringOrThrow(attributeSection, "attribute");
|
||||
Attribute attribute = Utilz.strToAttributeType(attributeStr);
|
||||
Attribute attribute = Utils.strToAttributeType(attributeStr);
|
||||
if (attribute == null)
|
||||
throwInvalidPropertyValue("attribute");
|
||||
@Nullable String slotStr = getStringOrThrow(attributeSection, "slot");
|
||||
EquipmentSlot slot = Utilz.strToVanillaEquipmentSlot(slotStr);
|
||||
EquipmentSlot slot = Utils.strToVanillaEquipmentSlot(slotStr);
|
||||
if (slot == null)
|
||||
throwInvalidPropertyValue("slot");
|
||||
|
||||
@@ -422,7 +431,7 @@ public class Customizations
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
if(ex instanceof InvalidCustomizationPropertyExtension)
|
||||
if(ex instanceof InvalidCustomizationPropertyException)
|
||||
{
|
||||
Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath());
|
||||
Main.msg.error(ex.getMessage());
|
||||
@@ -451,22 +460,22 @@ public class Customizations
|
||||
|
||||
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)
|
||||
{
|
||||
throw new InvalidCustomizationPropertyExtension("Missing property '" + name + "'.");
|
||||
throw new InvalidCustomizationPropertyException("Missing property '" + 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)
|
||||
{
|
||||
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)
|
||||
@@ -475,7 +484,7 @@ public class Customizations
|
||||
return;
|
||||
|
||||
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())
|
||||
{
|
||||
Customization customization = entry.getValue();
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package dev.lone.vanillacustomizer;
|
||||
|
||||
public class InvalidCustomizationPropertyExtension extends IllegalArgumentException
|
||||
{
|
||||
public InvalidCustomizationPropertyExtension(String text)
|
||||
{
|
||||
super(text);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public final class Main extends JavaPlugin implements Listener
|
||||
// https://game8.co/games/Minecraft/archives/378457#hl_1
|
||||
|
||||
//DO NOT SET AS "final" OR SPIGOT.MC won't replace it.
|
||||
@SuppressWarnings("unused")
|
||||
public static String b = "%%__USER__%%";
|
||||
public static Msg msg;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.lone.vanillacustomizer.commands;
|
||||
|
||||
import dev.lone.LoneLibs.annotations.NotNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.lone.vanillacustomizer.commands.registered;
|
||||
|
||||
import dev.lone.LoneLibs.annotations.NotNull;
|
||||
import dev.lone.vanillacustomizer.Main;
|
||||
import dev.lone.vanillacustomizer.commands.CommandRun;
|
||||
import dev.lone.vanillacustomizer.utils.SmallCaps;
|
||||
import fr.mrmicky.fastinv.FastInv;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -58,7 +58,11 @@ public class MainCommand extends CommandRun
|
||||
break;
|
||||
|
||||
case "small":
|
||||
|
||||
if(args.length < 2)
|
||||
{
|
||||
Main.msg.send(player, "Usage: /vanillacustomizer small <text>");
|
||||
return;
|
||||
}
|
||||
String text = args[1];
|
||||
Main.msg.send(player, SmallCaps.apply(text));
|
||||
break;
|
||||
@@ -130,6 +134,8 @@ public class MainCommand extends CommandRun
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, @NotNull String[] args)
|
||||
{
|
||||
if(args.length == 1)
|
||||
return List.of("reload", "showdebugtag", "small", "debugmenu");
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,29 @@ package dev.lone.vanillacustomizer.customization;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.vanillacustomizer.customization.changes.IChange;
|
||||
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.List;
|
||||
|
||||
public class Customization
|
||||
{
|
||||
public final boolean ignoreInventoriesEnabled;
|
||||
public final boolean ignoreAnyCustomInventory;
|
||||
public final List<String> ignoreInventoriesByTitle;
|
||||
|
||||
public List<IRule> rules = 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()
|
||||
{
|
||||
return rules.isEmpty() && changes.isEmpty();
|
||||
@@ -28,8 +41,24 @@ public class Customization
|
||||
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)
|
||||
{
|
||||
if(!rule.matches(session))
|
||||
|
||||
@@ -6,8 +6,8 @@ import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import dev.lone.LoneLibs.annotations.NotNull;
|
||||
import dev.lone.LoneLibs.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import dev.lone.LoneLibs.annotations.NotNull;
|
||||
import dev.lone.LoneLibs.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Deprecated //TODO
|
||||
@Deprecated //TODO implement this shit
|
||||
public class AttributesRemove implements IChange
|
||||
{
|
||||
Multimap<Attribute, AttributeModifier> modifiers;
|
||||
|
||||
@@ -5,8 +5,12 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.LoneLibs.chat.Comp;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
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;
|
||||
|
||||
public class LoreInsert implements IChange
|
||||
@@ -23,7 +27,41 @@ public class LoreInsert implements IChange
|
||||
@Override
|
||||
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");
|
||||
|
||||
if (!display.hasTag("Lore"))
|
||||
@@ -51,13 +89,31 @@ public class LoreInsert implements IChange
|
||||
lore.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line)));
|
||||
}
|
||||
}
|
||||
|
||||
session.saveNbt();
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
NBTList<String> lore = display.getStringList("Lore");
|
||||
|
||||
@@ -3,8 +3,11 @@ package dev.lone.vanillacustomizer.customization.changes;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
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.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.List;
|
||||
@@ -16,14 +19,40 @@ public class LoreInsertJson implements IChange
|
||||
|
||||
public LoreInsertJson(List<String> linesJson, int index)
|
||||
{
|
||||
this.linesJson = Utilz.fixJsonFormatting(linesJson);
|
||||
this.linesJson = Utils.fixJsonFormatting(linesJson);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
|
||||
List<String> newLinesJson = new ArrayList<>();
|
||||
@@ -39,14 +68,10 @@ public class LoreInsertJson implements IChange
|
||||
{
|
||||
NBTList<String> lore = display.getStringList("Lore");
|
||||
if (index < lore.size())
|
||||
{
|
||||
lore.addAll(index, newLinesJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
lore.addAll(newLinesJson);
|
||||
}
|
||||
}
|
||||
|
||||
session.saveNbt();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,13 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.LoneLibs.chat.Comp;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
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;
|
||||
|
||||
public class LoreSet implements IChange
|
||||
@@ -21,7 +26,23 @@ public class LoreSet implements IChange
|
||||
@Override
|
||||
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");
|
||||
|
||||
display.removeKey("Lore");
|
||||
|
||||
@@ -4,8 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -16,13 +17,24 @@ public class LoreSetJson implements IChange
|
||||
|
||||
public LoreSetJson(List<String> linesJson)
|
||||
{
|
||||
this.linesJson = Utilz.fixJsonFormatting(linesJson);
|
||||
this.linesJson = Utils.fixJsonFormatting(linesJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
|
||||
display.removeKey("Lore");
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ProtectNbtData implements IChange
|
||||
@Override
|
||||
public void apply(ChangeSession session)
|
||||
{
|
||||
NBTItem nbt = session.nbt();
|
||||
NBTItem nbt = session.nbtLegacy();
|
||||
nbt.removeKey("PublicBukkitValues");
|
||||
nbt.removeKey("itemsadder");
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.LoneLibs.chat.Comp;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
import dev.lone.vanillacustomizer.utils.ConfigFile;
|
||||
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Renamer implements IChange
|
||||
@@ -20,7 +22,15 @@ public class Renamer implements IChange
|
||||
@Override
|
||||
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");
|
||||
display.setString("Name", Comp.legacyToJson(IChange.replacePlaceholders(session, name)));
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
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
|
||||
{
|
||||
@@ -14,15 +16,24 @@ public class RenamerJson implements IChange
|
||||
{
|
||||
// This should validate if the json is valid and throw an exception if not.
|
||||
// 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
|
||||
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");
|
||||
display.setString("Name", IChange.replacePlaceholders(session, json));
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ReplaceCustomModelData implements IChange
|
||||
@Override
|
||||
public void apply(ChangeSession session)
|
||||
{
|
||||
NBTItem nbt = session.nbt();
|
||||
NBTItem nbt = session.nbtLegacy();
|
||||
nbt.setInteger("CustomModelData", id);
|
||||
|
||||
session.saveNbt();
|
||||
|
||||
@@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.LoneLibs.chat.Comp;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
import dev.lone.vanillacustomizer.utils.ConfigFile;
|
||||
import lonelibs.dev.lone.fastnbt.nms.nbt.NItem;
|
||||
|
||||
public class ReplaceWordDisplayName implements IChange
|
||||
{
|
||||
@@ -27,7 +29,15 @@ public class ReplaceWordDisplayName implements IChange
|
||||
|
||||
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");
|
||||
display.setString("Name", Comp.legacyToJson(name));
|
||||
|
||||
|
||||
@@ -5,10 +5,15 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem;
|
||||
import dev.lone.LoneLibs.nbt.nbtapi.NBTList;
|
||||
import dev.lone.vanillacustomizer.ChangeSession;
|
||||
import dev.lone.LoneLibs.chat.Comp;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
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.TextReplacementConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReplaceWordLore implements IChange
|
||||
{
|
||||
TextReplacementConfig textReplacement;
|
||||
@@ -27,7 +32,26 @@ public class ReplaceWordLore implements IChange
|
||||
@Override
|
||||
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");
|
||||
if(!display.hasTag("Lore"))
|
||||
return;
|
||||
@@ -36,7 +60,7 @@ public class ReplaceWordLore implements IChange
|
||||
for (int i = 0; i < lore.size(); i++)
|
||||
{
|
||||
String lineJson = lore.get(i);
|
||||
Component component = Comp.jsonToComponent(lineJson);
|
||||
Component component = Utils.jsonToComponent(lineJson);
|
||||
component = component.replaceText(textReplacement);
|
||||
lore.set(i, Comp.componentToJson(component));
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class RuleNbtMatcher implements IRule
|
||||
break;
|
||||
case NBTTagByte:
|
||||
nbtValue = Byte.parseByte(nbtValueStr);
|
||||
break;
|
||||
case NBTTagShort:
|
||||
nbtValue = Short.parseShort(nbtValueStr);
|
||||
break;
|
||||
@@ -71,17 +72,21 @@ public class RuleNbtMatcher implements IRule
|
||||
public boolean matches(ItemStack item)
|
||||
{
|
||||
NBTItem nbt = new NBTItem(item);
|
||||
|
||||
if (!nbt.hasTag(nbtPathSplit[0]))
|
||||
return false;
|
||||
|
||||
NBTCompound currentCompound = nbt.getCompound(nbtPathSplit[0]);
|
||||
if(currentCompound == null)
|
||||
return false;
|
||||
for (int i = 1; i < nbtPathSplit.length - 1; i++)
|
||||
{
|
||||
assert currentCompound != null;
|
||||
if (!currentCompound.hasTag(nbtPathSplit[i]))
|
||||
return false;
|
||||
currentCompound = currentCompound.getCompound(nbtPathSplit[i]);
|
||||
}
|
||||
|
||||
assert currentCompound != null;
|
||||
if (!currentCompound.hasTag(nbtPathSplit[nbtPathSplit.length - 1]))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.apache.commons.io.IOCase;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
@Deprecated // TODO: implement that shit
|
||||
public class WildcardsMatcher implements ITextMatcher
|
||||
{
|
||||
// private List<String> wildcardStart;
|
||||
|
||||
@@ -14,6 +14,8 @@ public class RulePlaceable implements IRule
|
||||
@Override
|
||||
public boolean matches(ItemStack item)
|
||||
{
|
||||
if(placeable)
|
||||
return item.getType().isBlock();
|
||||
return !item.getType().isBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.lone.vanillacustomizer.customization.rules;
|
||||
|
||||
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.meta.ItemMeta;
|
||||
|
||||
@@ -27,14 +27,14 @@ public class RuleVanillaItemMatcher implements IRule
|
||||
return true;
|
||||
|
||||
// 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())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: check if it has PersistentDataContainer, for example.
|
||||
|
||||
String displayName = meta.getDisplayName();
|
||||
displayName = Utilz.backColor(displayName);
|
||||
displayName = Utils.backColor(displayName);
|
||||
|
||||
// Check if italic, means that might have been renamed using anvil.
|
||||
return !displayName.startsWith("&o");
|
||||
@@ -49,6 +49,8 @@ public class RuleVanillaItemMatcher implements IRule
|
||||
@Override
|
||||
public boolean matches(ChangeSession session)
|
||||
{
|
||||
if(isVanilla)
|
||||
return session.isVanilla;
|
||||
return !session.isVanilla;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.lone.vanillacustomizer.exception;
|
||||
|
||||
public class InvalidCustomizationPropertyException extends IllegalArgumentException
|
||||
{
|
||||
public InvalidCustomizationPropertyException(String text)
|
||||
{
|
||||
super(text);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
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.vanillacustomizer.Main;
|
||||
import lonelibs.dev.lone.fastnbt.nms.Version;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
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.
|
||||
*/
|
||||
public class Nms
|
||||
public class NMS
|
||||
{
|
||||
public static boolean is_v18_2_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;
|
||||
public static boolean is_v1_1_20_5_or_greater;
|
||||
|
||||
static
|
||||
{
|
||||
is_v19_2_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_19_R1);
|
||||
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);
|
||||
is_v1_1_20_5_or_greater = Version.isAtLeast(Version.v1_20_5);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,9 +31,9 @@ public class Nms
|
||||
*/
|
||||
@Nullable
|
||||
@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
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.Material;
|
||||
import org.bukkit.inventory.CookingRecipe;
|
||||
@@ -17,7 +17,7 @@ public class ItemsNms
|
||||
|
||||
ItemsNms()
|
||||
{
|
||||
nms = Nms.findImplementation(IItemsNms.class, this, false);
|
||||
nms = NMS.findImplementation(IItemsNms.class, this, false);
|
||||
}
|
||||
|
||||
public static ItemsNms inst()
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.lone.vanillacustomizer.nms.items;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum Rarity
|
||||
{
|
||||
COMMON(Color.WHITE),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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.nms.Nms;
|
||||
import dev.lone.vanillacustomizer.nms.NMS;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -15,7 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import dev.lone.LoneLibs.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* 2020-01-08 LoneDev
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class ConfigFile
|
||||
{
|
||||
private static final Pattern hexPattern = Pattern.compile("%#([A-Fa-f0-9]){6}%");
|
||||
@@ -219,8 +220,6 @@ public class ConfigFile
|
||||
}
|
||||
|
||||
private static String convertColor0(String message)
|
||||
{
|
||||
if (Nms.is_v1_16_or_greater)
|
||||
{
|
||||
Matcher matcher = hexPattern.matcher(message);
|
||||
while (matcher.find())
|
||||
@@ -231,7 +230,6 @@ public class ConfigFile
|
||||
message = before + hexColor + after;
|
||||
matcher = hexPattern.matcher(message);
|
||||
}
|
||||
}
|
||||
return message.replace("&", "\u00A7");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.lone.vanillacustomizer.utils;
|
||||
|
||||
import dev.lone.LoneLibs.annotations.NotNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SmallCaps
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name: VanillaCustomizer
|
||||
version: 0.2
|
||||
version: 0.3
|
||||
main: dev.lone.vanillacustomizer.Main
|
||||
api-version: 1.13
|
||||
commands:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -46,23 +46,21 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>CopyFile</id>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<executable>cmd</executable>
|
||||
<workingDirectory>${project.parent.basedir}</workingDirectory>
|
||||
<arguments>
|
||||
<argument>/C</argument>
|
||||
<argument>.mvn-exec\CopyFile.bat</argument>
|
||||
</arguments>
|
||||
<target>
|
||||
<!-- Copy JAR to multiple directories -->
|
||||
<copy file="${basedir}/../output/${project.parent.artifactId}.jar" todir="C:/Progetti/Minecraft/TestServer/1.20.6/plugins/"/>
|
||||
<copy file="${basedir}/../output/${project.parent.artifactId}.jar" todir="C:/Progetti/Minecraft/TestServer/1.21.1/plugins/"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -84,38 +82,48 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</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>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_20_R3</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_20_R2</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_20_R1</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_19_R3</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_18_R2</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-nms-v1_17_R1</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_17_R1 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_18_R2 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_19_R3 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
55
VanillaCustomizer-nms-v1_20_6/pom.xml
Normal 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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_20_R1 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_20_R2 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<groupId>dev.lone</groupId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer-core</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class v1_20_R3 implements IItemsNms
|
||||
{
|
||||
@Override
|
||||
|
||||
55
VanillaCustomizer-nms-v1_21_1/pom.xml
Normal 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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
4
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.lone</groupId>
|
||||
<artifactId>VanillaCustomizer</artifactId>
|
||||
<version>VERSION</version>
|
||||
<version>1.0</version>
|
||||
|
||||
<name>VanillaCustomizer</name>
|
||||
<packaging>pom</packaging>
|
||||
@@ -22,6 +22,8 @@
|
||||
<modules>
|
||||
<module>VanillaCustomizer-core</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_R2</module>
|
||||
<module>VanillaCustomizer-nms-v1_20_R1</module>
|
||||
|
||||