mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-03 06:57:58 +01:00
Handle legacy item names for events, fixes #557. Bump version
This commit is contained in:
parent
2338c127fb
commit
e363cd4cb0
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<groupId>me.blackvein.quests</groupId>
|
<groupId>me.blackvein.quests</groupId>
|
||||||
<artifactId>quests</artifactId>
|
<artifactId>quests</artifactId>
|
||||||
<version>3.4.6</version>
|
<version>3.4.7</version>
|
||||||
<name>quests</name>
|
<name>quests</name>
|
||||||
<url>https://github.com/FlyingPikachu/Quests/</url>
|
<url>https://github.com/FlyingPikachu/Quests/</url>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -32,7 +32,6 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
|||||||
|
|
||||||
import me.blackvein.quests.util.ItemUtil;
|
import me.blackvein.quests.util.ItemUtil;
|
||||||
import me.blackvein.quests.util.Lang;
|
import me.blackvein.quests.util.Lang;
|
||||||
import me.blackvein.quests.util.MiscUtil;
|
|
||||||
import me.blackvein.quests.util.RomanNumeral;
|
import me.blackvein.quests.util.RomanNumeral;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.event.NPCDeathEvent;
|
import net.citizensnpcs.api.event.NPCDeathEvent;
|
||||||
|
@ -2600,22 +2600,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private ItemStack processItemStack(String questName, String material, int amount, short durability) {
|
|
||||||
try {
|
|
||||||
return new ItemStack(Material.matchMaterial(material), amount, durability);
|
|
||||||
} catch (Exception e) {
|
|
||||||
try {
|
|
||||||
getLogger().warning(material + " is invalid for quest " + questName + "! You may need to update your quests.yml "
|
|
||||||
+ "in accordance with https://github.com/FlyingPikachu/Quests/wiki/Item-Formatting#list");
|
|
||||||
return new ItemStack(Material.matchMaterial(material, true), amount, durability);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
getLogger().severe("Unable to use LEGACY_" + material + " for quest " + questName);
|
|
||||||
e2.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processStages(Quest quest, FileConfiguration config, String questName) throws StageFailedException {
|
private void processStages(Quest quest, FileConfiguration config, String questName) throws StageFailedException {
|
||||||
ConfigurationSection questStages = config.getConfigurationSection("quests." + questName + ".stages.ordered");
|
ConfigurationSection questStages = config.getConfigurationSection("quests." + questName + ".stages.ordered");
|
||||||
@ -2681,10 +2666,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
for (String s : breaknames) {
|
for (String s : breaknames) {
|
||||||
ItemStack is;
|
ItemStack is;
|
||||||
if (breakdurability.get(breaknames.indexOf(s)) != -1) {
|
if (breakdurability.get(breaknames.indexOf(s)) != -1) {
|
||||||
is = processItemStack(questName, s, breakamounts.get(breaknames.indexOf(s)), breakdurability.get(breaknames.indexOf(s)));
|
is = ItemUtil.processItemStack(s, breakamounts.get(breaknames.indexOf(s)), breakdurability.get(breaknames.indexOf(s)));
|
||||||
} else {
|
} else {
|
||||||
// Legacy
|
// Legacy
|
||||||
is = processItemStack(questName, s, breakamounts.get(breaknames.indexOf(s)), (short) 0);
|
is = ItemUtil.processItemStack(s, breakamounts.get(breaknames.indexOf(s)), (short) 0);
|
||||||
}
|
}
|
||||||
if (Material.matchMaterial(s) != null) {
|
if (Material.matchMaterial(s) != null) {
|
||||||
oStage.blocksToBreak.add(is);
|
oStage.blocksToBreak.add(is);
|
||||||
@ -2720,10 +2705,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
for (String s : damagenames) {
|
for (String s : damagenames) {
|
||||||
ItemStack is;
|
ItemStack is;
|
||||||
if (damagedurability.get(damagenames.indexOf(s)) != -1) {
|
if (damagedurability.get(damagenames.indexOf(s)) != -1) {
|
||||||
is = processItemStack(questName, s, damageamounts.get(damagenames.indexOf(s)), damagedurability.get(damagenames.indexOf(s)));
|
is = ItemUtil.processItemStack(s, damageamounts.get(damagenames.indexOf(s)), damagedurability.get(damagenames.indexOf(s)));
|
||||||
} else {
|
} else {
|
||||||
// Legacy
|
// Legacy
|
||||||
is = processItemStack(questName, s, damageamounts.get(damagenames.indexOf(s)), (short) 0);
|
is = ItemUtil.processItemStack(s, damageamounts.get(damagenames.indexOf(s)), (short) 0);
|
||||||
}
|
}
|
||||||
if (Material.matchMaterial(s) != null) {
|
if (Material.matchMaterial(s) != null) {
|
||||||
oStage.blocksToDamage.add(is);
|
oStage.blocksToDamage.add(is);
|
||||||
@ -2759,10 +2744,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
for (String s : placenames) {
|
for (String s : placenames) {
|
||||||
ItemStack is;
|
ItemStack is;
|
||||||
if (placedurability.get(placenames.indexOf(s)) != -1) {
|
if (placedurability.get(placenames.indexOf(s)) != -1) {
|
||||||
is = processItemStack(questName, s, placeamounts.get(placenames.indexOf(s)), placedurability.get(placenames.indexOf(s)));
|
is = ItemUtil.processItemStack(s, placeamounts.get(placenames.indexOf(s)), placedurability.get(placenames.indexOf(s)));
|
||||||
} else {
|
} else {
|
||||||
// Legacy
|
// Legacy
|
||||||
is = processItemStack(questName, s, placeamounts.get(placenames.indexOf(s)), (short) 0);
|
is = ItemUtil.processItemStack(s, placeamounts.get(placenames.indexOf(s)), (short) 0);
|
||||||
}
|
}
|
||||||
if (Material.matchMaterial(s) != null) {
|
if (Material.matchMaterial(s) != null) {
|
||||||
oStage.blocksToPlace.add(is);
|
oStage.blocksToPlace.add(is);
|
||||||
@ -2798,10 +2783,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
for (String s : usenames) {
|
for (String s : usenames) {
|
||||||
ItemStack is;
|
ItemStack is;
|
||||||
if (usedurability.get(usenames.indexOf(s)) != -1) {
|
if (usedurability.get(usenames.indexOf(s)) != -1) {
|
||||||
is = processItemStack(questName, s, useamounts.get(usenames.indexOf(s)), usedurability.get(usenames.indexOf(s)));
|
is = ItemUtil.processItemStack(s, useamounts.get(usenames.indexOf(s)), usedurability.get(usenames.indexOf(s)));
|
||||||
} else {
|
} else {
|
||||||
// Legacy
|
// Legacy
|
||||||
is = processItemStack(questName, s, useamounts.get(usenames.indexOf(s)), (short) 0);
|
is = ItemUtil.processItemStack(s, useamounts.get(usenames.indexOf(s)), (short) 0);
|
||||||
}
|
}
|
||||||
if (Material.matchMaterial(s) != null) {
|
if (Material.matchMaterial(s) != null) {
|
||||||
oStage.blocksToUse.add(is);
|
oStage.blocksToUse.add(is);
|
||||||
@ -2837,10 +2822,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
for (String s : cutnames) {
|
for (String s : cutnames) {
|
||||||
ItemStack is;
|
ItemStack is;
|
||||||
if (cutdurability.get(cutnames.indexOf(s)) != -1) {
|
if (cutdurability.get(cutnames.indexOf(s)) != -1) {
|
||||||
is = processItemStack(questName, s, cutamounts.get(cutnames.indexOf(s)), cutdurability.get(cutnames.indexOf(s)));
|
is = ItemUtil.processItemStack(s, cutamounts.get(cutnames.indexOf(s)), cutdurability.get(cutnames.indexOf(s)));
|
||||||
} else {
|
} else {
|
||||||
// Legacy
|
// Legacy
|
||||||
is = processItemStack(questName, s, cutamounts.get(cutnames.indexOf(s)), (short) 0);
|
is = ItemUtil.processItemStack(s, cutamounts.get(cutnames.indexOf(s)), (short) 0);
|
||||||
}
|
}
|
||||||
if (Material.matchMaterial(s) != null) {
|
if (Material.matchMaterial(s) != null) {
|
||||||
oStage.blocksToCut.add(is);
|
oStage.blocksToCut.add(is);
|
||||||
|
@ -96,6 +96,32 @@ public class ItemUtil {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an ItemStack based on given values. Checks for legacy pre-1.13 names. Other traits such as
|
||||||
|
* enchantments and lore cannot be added via this method and must be done separately.
|
||||||
|
*
|
||||||
|
* @param material Item name suitable for Material.matchMaterial()
|
||||||
|
* @param amount The number of items in the stack
|
||||||
|
* @param durability The data value of the item, default of 0
|
||||||
|
* @return ItemStack, or null if invalid format
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static ItemStack processItemStack(String material, int amount, short durability) {
|
||||||
|
try {
|
||||||
|
return new ItemStack(Material.matchMaterial(material), amount, durability);
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
Bukkit.getLogger().warning(material + " is invalid! You may need to update your quests.yml or events.yml "
|
||||||
|
+ "in accordance with https://github.com/FlyingPikachu/Quests/wiki/Item-Formatting#list");
|
||||||
|
return new ItemStack(Material.matchMaterial(material, true), amount, durability);
|
||||||
|
} catch (Exception e2) {
|
||||||
|
Bukkit.getLogger().severe("Unable to use LEGACY_" + material + " for as item name");
|
||||||
|
e2.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ItemStack from formatted string. See serialize() for reverse function.
|
* Get ItemStack from formatted string. See serialize() for reverse function.
|
||||||
@ -112,27 +138,24 @@ public class ItemUtil {
|
|||||||
}
|
}
|
||||||
ItemStack stack = null;
|
ItemStack stack = null;
|
||||||
String[] args = data.split(":");
|
String[] args = data.split(":");
|
||||||
ItemMeta meta = null;
|
String name = null;
|
||||||
EnchantmentStorageMeta esmeta = null;
|
int amount = 0;
|
||||||
|
short durability = 0;
|
||||||
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
||||||
String display = null;
|
String display = null;
|
||||||
LinkedList<String> lore = new LinkedList<String>();
|
LinkedList<String> lore = new LinkedList<String>();
|
||||||
LinkedHashMap<Enchantment, Integer> stored = new LinkedHashMap<Enchantment, Integer>();
|
LinkedHashMap<Enchantment, Integer> stored = new LinkedHashMap<Enchantment, Integer>();
|
||||||
LinkedHashMap<String, Object> extra = new LinkedHashMap<String, Object>();
|
LinkedHashMap<String, Object> extra = new LinkedHashMap<String, Object>();
|
||||||
|
ItemMeta meta = null;
|
||||||
|
EnchantmentStorageMeta esmeta = null;
|
||||||
for (String targ : args) {
|
for (String targ : args) {
|
||||||
String arg = targ.replace("minecraft|", "minecraft:");
|
String arg = targ.replace("minecraft|", "minecraft:");
|
||||||
if (arg.startsWith("name-")) {
|
if (arg.startsWith("name-")) {
|
||||||
try {
|
name = arg.substring(5).toUpperCase();
|
||||||
stack = new ItemStack(Material.matchMaterial(arg.substring(5).toUpperCase()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().severe("[Quests] The item name \'" + arg.substring(5).toUpperCase() + "\' is invalid. Make sure quests.yml is UTF-8 encoded");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
meta = stack.getItemMeta();
|
|
||||||
} else if (arg.startsWith("amount-")) {
|
} else if (arg.startsWith("amount-")) {
|
||||||
stack.setAmount(Integer.parseInt(arg.substring(7)));
|
amount = Integer.parseInt(arg.substring(7));
|
||||||
} else if (arg.startsWith("data-")) {
|
} else if (arg.startsWith("data-")) {
|
||||||
stack.setDurability(Short.parseShort(arg.substring(5)));
|
durability = Short.parseShort(arg.substring(5));
|
||||||
} else if (arg.startsWith("enchantment-")) {
|
} else if (arg.startsWith("enchantment-")) {
|
||||||
String[] temp = arg.substring(12).split(" ");
|
String[] temp = arg.substring(12).split(" ");
|
||||||
try {
|
try {
|
||||||
@ -196,7 +219,11 @@ public class ItemUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stack = processItemStack(name, amount, durability);
|
||||||
|
if (stack == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
meta = stack.getItemMeta();
|
||||||
if (!extra.isEmpty()) {
|
if (!extra.isEmpty()) {
|
||||||
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map<String, Object>) extra);
|
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map<String, Object>) extra);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user