Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
nbt matcher byte value not working	PluginBugs/Issues-VanillaCustomizer#12
1.21.1 support	PluginBugs/Issues-VanillaCustomizer#11
1.20.6 support	PluginBugs/Issues-VanillaCustomizer#10
`is_vanilla_item: false` not working correctly	PluginBugs/Issues-VanillaCustomizer#9
Newest LoneLibs support	PluginBugs/Issues-VanillaCustomizer#8
Ignoring inventory rule is ignored	PluginBugs/Issues-VanillaCustomizer#7
ERROR -> /vanillacustomizer small	PluginBugs/Issues-VanillaCustomizer#5
Invalid NBT match rule	PluginBugs/Issues-VanillaCustomizer#4
  • Loading branch information
LoneDev6 committed Sep 4, 2024
1 parent 9d5ee5a commit 13f3cd1
Show file tree
Hide file tree
Showing 62 changed files with 803 additions and 774 deletions.
Binary file added .assets/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/banner_big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/product_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/screenshots/screen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/screenshots/screen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/screenshots/screen3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/screenshots/screen4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ buildNumber.properties

# Common working directory
run/

# My stuff
/.cache/
/output/
/.paper-nms/
/custom_mapping.txt
/.assets/
target
/output/

1 change: 0 additions & 1 deletion .mvn-exec/CopyFile.bat

This file was deleted.

62 changes: 50 additions & 12 deletions VanillaCustomizer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
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;

// TODO: find a better name for this
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
Expand All @@ -32,23 +38,38 @@ public ChangeSession(ItemStack item, boolean trackChanges)
isVanilla = RuleVanillaItemMatcher.satisfy(item);
}

public Player getPlayer()
{
return player;
}

public ItemMeta refreshMeta()
{
// Meta always needs to be refreshed as Spigot caches it!
meta = item.getItemMeta();
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;
}

Expand All @@ -59,12 +80,14 @@ public NBTItem nbt()
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()
Expand All @@ -80,7 +103,7 @@ public boolean hasChanged()

public void refreshAll()
{
refreshNbt();
refreshNBT();
refreshMeta();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

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.*;
Expand Down Expand Up @@ -39,13 +40,21 @@ public void load()
{
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;

Expand Down Expand Up @@ -169,7 +178,7 @@ public void load()
}
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());
Expand Down Expand Up @@ -282,10 +291,10 @@ public void load()
}
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]));
Expand All @@ -298,7 +307,7 @@ else if (tmp.length == 2)
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);
Expand All @@ -324,7 +333,7 @@ else if (tmp.length == 3)
}
else if (tmp.length == 2)
{
if (Utilz.isNumeric(tmp[1]))
if (Utils.isNumeric(tmp[1]))
{
enchant = Enchantment.getByName(tmp[0]);
if (enchant == null)
Expand Down Expand Up @@ -360,11 +369,11 @@ else if (tmp.length == 3)
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");

Expand Down Expand Up @@ -422,7 +431,7 @@ else if (tmp.length == 3)
}
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());
Expand Down Expand Up @@ -451,22 +460,22 @@ private String getStringOrThrow(ConfigurationSection section, String name)

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)
Expand All @@ -475,7 +484,7 @@ public void handle(ItemStack itemStack, Player player)
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();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 13f3cd1

Please sign in to comment.