Skip to content

Commit

Permalink
📦 同步主仓库 (7943dcc3109ec777b33b4269901042d0864f18ae)
Browse files Browse the repository at this point in the history
  • Loading branch information
INSide-734 committed Aug 15, 2024
1 parent 56bb46e commit dcb8d33
Show file tree
Hide file tree
Showing 35 changed files with 210 additions and 202 deletions.
2 changes: 1 addition & 1 deletion MMOItems-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<dependency>
<groupId>io.lumine</groupId>
<artifactId>Mythic-Dist</artifactId>
<version>5.6.0-SNAPSHOT</version>
<version>5.7.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
12 changes: 2 additions & 10 deletions MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.manager.TypeManager;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.Validate;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void load(@NotNull ConfigurationSection config) {
postLoadAction.cacheConfig(config);

name = config.getString("name", name);
item = read(config.getString("display", item == null ? Material.STONE.toString() : item.getType().toString()));
item = MMOUtils.readIcon(config.getString("display", item == null ? Material.STONE.toString() : item.getType().toString()));
(unidentifiedTemplate = new UnidentifiedItem(this)).update(config.getConfigurationSection("unident-item"));
loreFormat = config.getString("LoreFormat", (parent != null ? parent.loreFormat : null));
attackCooldownKey = config.getString("attack-cooldown-key", "default");
Expand Down Expand Up @@ -286,14 +286,6 @@ public UnidentifiedItem getUnidentifiedTemplate() {
return unidentifiedTemplate;
}

private ItemStack read(String str) {
Validate.notNull(str, "Input must not be null");

String[] split = str.split(":");
Material material = Material.valueOf(split[0]);
return split.length > 1 ? MythicLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1])) : new ItemStack(material);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.Indyuce.mmoitems.api.crafting.ingredient.inventory;

import com.google.gson.JsonParser;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.gson.JsonParser;

public class MMOItemPlayerIngredient extends PlayerIngredient {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.Indyuce.mmoitems.api.interaction.util;

import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.gson.JsonParser;
import io.lumine.mythic.lib.gson.JsonSyntaxException;
import io.lumine.mythic.lib.version.VEnchantment;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.event.item.CustomDurabilityDamage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.Indyuce.mmoitems.api.item.build;

import com.google.gson.JsonArray;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.gson.JsonArray;
import io.lumine.mythic.lib.util.AdventureUtils;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmoitems.ItemStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
import java.util.List;
import java.util.stream.Collectors;

// TODO Refactor this mess
public class ConfigItem {
private final String id;
@Deprecated
private final ItemStack icon;

// updated when the plugin reloads
private String name;
private List<String> lore;

// generated
@Deprecated
private ItemStack item;

public ConfigItem(String id, Material material) {
Expand All @@ -44,8 +47,8 @@ public ConfigItem(String id, Material material, String name, String... lore) {
this.lore = Arrays.asList(lore);
}

/*
* used as util to load an item stack from a config
/**
* Used as util to load an item stack from a config
*/
public ConfigItem(ConfigurationSection config) {
Validate.notNull(config, "Config cannot be null");
Expand All @@ -65,11 +68,13 @@ public String getId() {
return id;
}

@Deprecated
public void setup(ConfigurationSection config) {
config.set("name", getName());
config.set("lore", getLore());
}

@Deprecated
public void update(ConfigurationSection config) {
Validate.notNull(config, "Config cannot be null");

Expand Down Expand Up @@ -128,10 +133,12 @@ public boolean hasLore() {
return lore != null;
}

@Deprecated
public ItemStack getItem() {
return item;
}

@Deprecated
public ItemStack getNewItem() {
return item.clone();
}
Expand All @@ -144,11 +151,11 @@ protected void setLore(List<String> lore) {
this.lore = lore;
}

@Deprecated
protected void setItem(ItemStack item) {
this.item = item;
}


/**
* Unidentified items are ruined when, using a custom resourcepack, they get the material and
* custom model data of what they should be, making them not really unidentified.... this will
Expand All @@ -159,11 +166,13 @@ protected void setItem(ItemStack item) {
* @author Gunging
* @see #setModel(Integer)
*/
@Deprecated
protected void setMaterial(@Nullable Material mat) {
material = mat;
}

@Nullable
@Deprecated
protected Material material = null;

/**
Expand All @@ -176,10 +185,12 @@ protected void setMaterial(@Nullable Material mat) {
* @author Gunging
* @see #setMaterial(Material)
*/
@Deprecated
protected void setModel(@Nullable Integer cmd) {
customModelData = cmd;
}

@Nullable
@Deprecated
protected Integer customModelData = null;
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
package net.Indyuce.mmoitems.api.item.util.identify;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

import io.lumine.mythic.lib.api.item.NBTItem;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class IdentifiedItem {
private final NBTItem item;

public IdentifiedItem(NBTItem item) {
this.item = item;
}

/*
* the identified item is stored in an item NBTTag, identifying the item
* basically replaces the item for the one saved in the NBT
*/
public ItemStack identify() {
return deserialize(item.getString("MMOITEMS_UNIDENTIFIED_ITEM"));
}

private ItemStack deserialize(String data) {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
ItemStack stack = (ItemStack) dataInput.readObject();
dataInput.close();

/*
* For some reason, unidentified items keep having slightly different NBT tags
* than items generated from mob drops or the GUI, I suppose it has to do with
* the serialization-deserialization, It seems to get fixed when rebuilding
* the item stack though.
*
* Its annoying because it prevents stacking.
*/
NBTItem toRebuild = NBTItem.get(stack);
if (toRebuild.hasType()) {

// Rebuild
LiveMMOItem rebuilt = new LiveMMOItem(stack);
return rebuilt.newBuilder().build(); }

return stack;
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
return null;
}
}
private final NBTItem item;

public IdentifiedItem(NBTItem item) {
this.item = item;
}

/**
* The identified item is stored in an item NBTTag, identifying the
* item basically replaces the item for the one saved in the NBT
*/
@NotNull
public ItemStack identify() {
return deserialize(item.getString("MMOITEMS_UNIDENTIFIED_ITEM"));
}

@NotNull
private ItemStack deserialize(String stringInput) {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(stringInput));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
ItemStack stack = (ItemStack) dataInput.readObject();
dataInput.close();

/*
* For some reason, unidentified items keep having slightly different NBT tags
* than items generated from mob drops or the GUI, I suppose it has to do with
* the serialization-deserialization, It seems to get fixed when rebuilding
* the item stack though.
*
* Its annoying because it prevents stacking.
*/
NBTItem toRebuild = NBTItem.get(stack);
if (toRebuild.hasType()) {

// Rebuild
LiveMMOItem rebuilt = new LiveMMOItem(stack);
return rebuilt.newBuilder().build();
}

return stack;
} catch (ClassNotFoundException | IOException exception) {
throw new RuntimeException(exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

Expand All @@ -23,11 +24,17 @@

public class UnidentifiedItem extends ConfigItem {
public UnidentifiedItem(Type type) {
// Default options
super("unidentified", type.getItem().getType());

setName("#prefix#Unidentified " + type.getName());
setLore(Arrays.asList("&7This item is unidentified. I must", "&7find a way to identify it!", "{tier}", "{tier}&8Item Info:",
"{range}&8- &7Lvl Range: &e#range#", "{tier}&8- &7Item Tier: #prefix##tier#"));
setLore(Arrays.asList(
"&7This item is unidentified. I must",
"&7find a way to identify it!",
"{tier}",
"{tier}&8Item Info:",
"{range}&8- &7Lvl Range: &e#range#",
"{tier}&8- &7Item Tier: #prefix##tier#"
));
}

public ItemBuilder newBuilder(NBTItem item) {
Expand Down Expand Up @@ -86,37 +93,36 @@ public ItemStack build() {

// Apply changes to item
item.getItem().setAmount(1);
ItemStack unidentified = MythicLib.plugin.getVersion().getWrapper().copyTexture(item)
.addTag(new ItemTag("MMOITEMS_UNIDENTIFIED_ITEM", serialize(item.toItem()))).toItem();

// Save serialized item inside of NBT
final ItemStack unidentified = NBTItem.get(new ItemStack(material != null ? material : item.getItem().getType()))
.addTag(new ItemTag("MMOITEMS_UNIDENTIFIED_ITEM", serialize(item.getItem())))
.toItem();

final ItemMeta meta = unidentified.getItemMeta();
if (customModelData != null) meta.setCustomModelData(customModelData);
else if (item.getItem().hasItemMeta() && item.getItem().getItemMeta().hasCustomModelData())
meta.setCustomModelData(item.getItem().getItemMeta().getCustomModelData());
unidentified.setAmount(amount);
ItemMeta meta = unidentified.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setUnbreakable(true);
AdventureUtils.setDisplayName(meta, name);
AdventureUtils.setLore(meta, lore);
if (customModelData != null) {
meta.setCustomModelData(customModelData);
}
unidentified.setItemMeta(meta);

// Has model?
if (material != null && material.isItem()) {
unidentified.setType(material);
}

return unidentified;
}

@NotNull
private String serialize(ItemStack item) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
dataOutput.writeObject(item);
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
e.printStackTrace();
return null;
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.Indyuce.mmoitems.stat;

import com.google.gson.*;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.gson.*;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import io.lumine.mythic.lib.util.annotation.BackwardsCompatibility;
import net.Indyuce.mmoitems.MMOItems;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package net.Indyuce.mmoitems.stat;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.gson.JsonObject;
import io.lumine.mythic.lib.gson.JsonParser;
import io.lumine.mythic.lib.gson.JsonSyntaxException;
import io.lumine.mythic.lib.version.VParticle;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
Expand Down
Loading

0 comments on commit dcb8d33

Please sign in to comment.