Skip to content

Commit

Permalink
v1.2.14 snapshot
Browse files Browse the repository at this point in the history
- fixed IA compatibility
- added NBT support
- added ItemUtils#compare(...) methods
  • Loading branch information
AlbeMiglio committed Apr 27, 2024
1 parent bb4b80e commit 5ecccd1
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 78 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Development builds are always available at: **https://ci.codemc.io/job/AlbeMigli
<dependency>
<groupId>it.mycraft</groupId>
<artifactId>powerlib-<YOUR-PLATFORM></artifactId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -61,7 +61,7 @@ repositories {
}
dependencies {
compileOnly 'it.mycraft:powerlib-<YOUR-PLATFORM>:1.2.13-SNAPSHOT'
compileOnly 'it.mycraft:powerlib-<YOUR-PLATFORM>:1.2.14-SNAPSHOT'
}
```

Expand All @@ -82,7 +82,7 @@ your plugin and rename its packages:
<dependency>
<groupId>it.mycraft</groupId>
<artifactId>powerlib-<YOUR-PLATFORM></artifactId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 5 additions & 1 deletion bukkit-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down Expand Up @@ -58,6 +58,10 @@
<pattern>org.bstats</pattern>
<shadedPattern>it.mycraft.powerlib.bukkit.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>de.tr7zw.changeme.nbtapi</pattern>
<shadedPattern>it.mycraft.powerlib.bukkit.nbtapi</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
Expand Down
2 changes: 1 addition & 1 deletion bukkit-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# PowerLib v1.2.13-SNAPSHOT
# PowerLib v1.2.14-SNAPSHOT
#
check-for-updates: true
2 changes: 1 addition & 1 deletion bukkit-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PowerLib
authors: [AlbeMiglio, FranFrau]
main: it.mycraft.powerlib.bukkit.PowerLibPlugin
version: 1.2.13-SNAPSHOT
version: 1.2.14-SNAPSHOT
14 changes: 12 additions & 2 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -34,6 +34,10 @@
<id>jitpack-repo</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -58,9 +62,15 @@
<dependency>
<groupId>com.github.LoneDev6</groupId>
<artifactId>api-itemsadder</artifactId>
<version>3.5.0c-r5</version>
<version>3.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package it.mycraft.powerlib.bukkit.item;

import com.google.common.base.Enums;
import com.google.common.base.Optional;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import dev.lone.itemsadder.api.ItemsAdder;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.CustomStack;
import it.mycraft.powerlib.bukkit.config.ConfigurationAdapter;
import it.mycraft.powerlib.bukkit.reflection.ReflectionAPI;
import it.mycraft.powerlib.common.chat.Message;
Expand Down Expand Up @@ -35,7 +36,7 @@

public class ItemBuilder implements Cloneable {

private static boolean usingItemsAdder = Bukkit.getPluginManager().isPluginEnabled("ItemsAdder");
public static boolean isUsingItemsAdder() { return Bukkit.getPluginManager().isPluginEnabled("ItemsAdder"); }
@Getter
private String material;
@Getter
Expand All @@ -57,19 +58,14 @@ public class ItemBuilder implements Cloneable {
@Getter
private HashMap<String, Object> placeholders;
private SkullMeta skullMeta;

/**
* @since 1.2.11
*/
@Getter
private HashMap<String, Pair<PersistentDataType, Object>> NBT;
private Pair<Optional<String>, Optional<String>> itemsAdderData;

public ItemBuilder() {
lore = new ArrayList<>();
enchantments = new HashMap<>();
potions = new HashMap<>();
placeholders = new HashMap<>();
NBT = new HashMap<>();
itemsAdderData = new Pair<>(Optional.empty(), Optional.empty());
}

/**
Expand All @@ -91,7 +87,7 @@ public ItemBuilder setMaterial(Material material) {
*/
public ItemBuilder setMaterial(String material) {
if (!material.startsWith("itemsadder:")) {
Optional<Material> optMaterial = Enums.getIfPresent(Material.class, material);
Optional<Material> optMaterial = Enums.getIfPresent(Material.class, material).toJavaUtil();
if (optMaterial.isPresent())
this.material = optMaterial.get().toString();
} else {
Expand Down Expand Up @@ -159,7 +155,7 @@ public ItemBuilder setLore(List<String> lore) {
/**
* Sets the item's enchantment
*
* @param enchantment The enchant
* @param enchantment The enchantment
* @param level The level
* @return The ItemBuilder
*/
Expand Down Expand Up @@ -269,6 +265,10 @@ public ItemBuilder setCustomModelData(int customModelData) {
* @return The ItemBuilder
*/
public ItemBuilder clone(ItemStack itemStack) {
if(itemStack == null || itemStack.getType() == Material.AIR) {
return this;
}

ItemMeta itemMeta = itemStack.getItemMeta();
material = itemStack.getType().toString();
amount = itemStack.getAmount();
Expand Down Expand Up @@ -302,13 +302,10 @@ public ItemBuilder clone(ItemStack itemStack) {
}
}

for (NamespacedKey key : itemMeta.getPersistentDataContainer().getKeys()) {
for (PersistentDataType type : PersistentDataTypes.values()) {
if (itemMeta.getPersistentDataContainer().has(key, type)) {
Object value = itemMeta.getPersistentDataContainer().get(key, type);
NBT.put(key.toString(), new Pair<>(type, value));
}
}
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound comp = nbtItem.getCompound("itemsadder");
if(isUsingItemsAdder() && comp != null) {
itemsAdderData = new Pair<>(Optional.ofNullable(comp.getString("namespace")), Optional.ofNullable(comp.getString("id")));
}
return this;
}
Expand Down Expand Up @@ -411,10 +408,10 @@ public ItemStack build() {
}
String name = this.name;
List<String> lore = this.lore == null ? null : new ArrayList<>(this.lore);
if (material.startsWith("itemsadder:")) {
if (material.startsWith("itemsadder:") && isUsingItemsAdder()) {
String customItem = material.replace("itemsadder:", "");
if (usingItemsAdder && ItemsAdder.isCustomItem(customItem)) {
this.clone(ItemsAdder.getCustomItem(customItem));
if (CustomStack.isInRegistry(customItem)) {
this.clone(CustomStack.getInstance(customItem).getItemStack());
} else material = "BARRIER";
}
Material m = Material.getMaterial(material);
Expand Down Expand Up @@ -446,12 +443,6 @@ public ItemStack build() {
itemMeta.setCustomModelData(customModelData);
}

NBT.entrySet().forEach((entry) -> {
itemMeta.getPersistentDataContainer()
.set(NamespacedKey.fromString(entry.getKey()),
entry.getValue().getLeft(), entry.getValue().getRight());
});

itemStack.setItemMeta(itemMeta);

if (m == Material.POTION && !potions.isEmpty()) {
Expand All @@ -461,6 +452,14 @@ public ItemStack build() {
}
itemStack.setItemMeta(potionMeta);
}

if(itemsAdderData.getLeft().isPresent() && itemsAdderData.getRight().isPresent()) {
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound comp = nbtItem.getOrCreateCompound("itemsadder");
comp.setString("namespace", itemsAdderData.getLeft().get());
comp.setString("id", itemsAdderData.getRight().get());
nbtItem.applyNBT(itemStack);
}
return itemStack;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.mycraft.powerlib.bukkit.item;

import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.CustomStack;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

public class ItemUtils {

public static boolean compare(ItemStack i1, ItemStack i2, boolean ignoreAmount) {
if (i1 == null || i2 == null || i1.getType() == Material.AIR || i2.getType() == Material.AIR) return false;
if (i1 == i2) return true;
if ((i1.getAmount() != i2.getAmount()) && !(ignoreAmount)) return false;
Material comparisonType = (i1.getType().isLegacy()) ? Bukkit.getUnsafe().fromLegacy(i1.getData(), true) : i1.getType();
return comparisonType == i2.getType()
&& i1.getDurability() == i2.getDurability()
&& i1.hasItemMeta() == i2.hasItemMeta()
&& new NBTItem(i1).getCompound().equals(new NBTItem(i2).getCompound());
}

public static boolean compare(ItemStack i1, ItemStack i2) {
return compare(i1, i2, true);
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion bungee-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bungee-plugin/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: PowerLib
author: AlbeMiglio
authors: [AlbeMiglio, FranFrau]
main: it.mycraft.powerlib.bungee.PowerLibPlugin
version: 1.2.13-SNAPSHOT
version: 1.2.14-SNAPSHOT
2 changes: 1 addition & 1 deletion bungee-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# PowerLib v1.2.13-SNAPSHOT
# PowerLib v1.2.14-SNAPSHOT
#
check-for-updates: true
2 changes: 1 addition & 1 deletion bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<packaging>pom</packaging>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
<licenses>
<license>
<name>MIT License</name>
Expand Down
2 changes: 1 addition & 1 deletion velocity-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.nio.file.Path;

@Getter
@Plugin(id = "powerlib", name = "PowerLib", version = "1.2.13-SNAPSHOT", authors = {"AlbeMiglio", "FranFrau"})
@Plugin(id = "powerlib", name = "PowerLib", version = "1.2.14-SNAPSHOT", authors = {"AlbeMiglio", "FranFrau"})
public class PowerLibPlugin {

private ProxyServer proxy;
Expand Down
2 changes: 1 addition & 1 deletion velocity-plugin/src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"id":"powerlib","name":"PowerLib","version":"1.2.13-SNAPSHOT","authors":["AlbeMiglio","FranFrau"],
{"id":"powerlib","name":"PowerLib","version":"1.2.14-SNAPSHOT","authors":["AlbeMiglio","FranFrau"],
"dependencies":[],"main":"it.mycraft.powerlib.velocity.PowerLibPlugin"}
2 changes: 1 addition & 1 deletion velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.13-SNAPSHOT</version>
<version>1.2.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 5ecccd1

Please sign in to comment.