mirror of
https://github.com/PikaMug/Quests.git
synced 2024-12-22 17:17:38 +01:00
* Item system improved.
This commit is contained in:
parent
8bbf21f0b5
commit
fc745501e5
@ -1,75 +1,19 @@
|
|||||||
package me.blackvein.quests;
|
package me.blackvein.quests;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import org.bukkit.Material;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class ItemData {
|
public class ItemData {
|
||||||
|
|
||||||
public HashMap<String, Data> map = new HashMap<String, Data>();
|
public static Material getMaterial(String name) {
|
||||||
private static ItemData instance = null;
|
Material material = Material.matchMaterial(name);
|
||||||
|
if (material == null) {
|
||||||
public static ItemData getInstance() {
|
name = name.toUpperCase().replace(" ", "_");
|
||||||
if (instance != null) {
|
for (Material mat : Material.values()) {
|
||||||
return instance;
|
if (mat.toString().contains(name)) {
|
||||||
} else {
|
return mat;
|
||||||
instance = new ItemData();
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemData() {
|
|
||||||
Scanner scanner = new Scanner(this.getClass().getClassLoader().getResourceAsStream("items.txt"));
|
|
||||||
|
|
||||||
while(scanner.hasNextLine()) {
|
|
||||||
String[] line = scanner.nextLine().split("=");
|
|
||||||
if (line.length > 1) {
|
|
||||||
String[] name = line[0].split(",");
|
|
||||||
Data data;
|
|
||||||
|
|
||||||
String[] str = line[1].split(",");
|
|
||||||
|
|
||||||
int id = -1;
|
|
||||||
byte mdata = 0;
|
|
||||||
try {
|
|
||||||
id = Integer.parseInt(str[0]);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
}
|
|
||||||
if (str.length > 1) {
|
|
||||||
mdata = Byte.parseByte(str[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String n : name) {
|
|
||||||
data = new Data(n, id, mdata);
|
|
||||||
map.put(n, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return material;
|
||||||
public Data getItem(String input) {
|
|
||||||
if (map.containsKey(input)) {
|
|
||||||
return map.get(input);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Data {
|
|
||||||
private final String name_;
|
|
||||||
private final int id_;
|
|
||||||
private final byte data_;
|
|
||||||
|
|
||||||
public Data(String name, int id, byte mdata) {
|
|
||||||
this.name_ = name;
|
|
||||||
this.id_ = id;
|
|
||||||
this.data_ = mdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getData() {
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import me.blackvein.quests.util.ItemUtil;
|
import me.blackvein.quests.util.ItemUtil;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -1169,7 +1171,7 @@ public class Quester {
|
|||||||
fishCaught = 0;
|
fishCaught = 0;
|
||||||
|
|
||||||
if (currentStage.itemsToEnchant.isEmpty() == false) {
|
if (currentStage.itemsToEnchant.isEmpty() == false) {
|
||||||
for (Entry e : currentStage.itemsToEnchant.entrySet()) {
|
for (Entry<Map<Enchantment, Material>, Integer> e : currentStage.itemsToEnchant.entrySet()) {
|
||||||
|
|
||||||
Map<Enchantment, Material> map = (Map<Enchantment, Material>) e.getKey();
|
Map<Enchantment, Material> map = (Map<Enchantment, Material>) e.getKey();
|
||||||
itemsEnchanted.put(map, 0);
|
itemsEnchanted.put(map, 0);
|
||||||
@ -1700,11 +1702,11 @@ public class Quester {
|
|||||||
LinkedList<Integer> itemIds = new LinkedList<Integer>();
|
LinkedList<Integer> itemIds = new LinkedList<Integer>();
|
||||||
LinkedList<Integer> enchAmounts = new LinkedList<Integer>();
|
LinkedList<Integer> enchAmounts = new LinkedList<Integer>();
|
||||||
|
|
||||||
for (Entry e : itemsEnchanted.entrySet()) {
|
for (Entry<Map<Enchantment, Material>, Integer> e : itemsEnchanted.entrySet()) {
|
||||||
|
|
||||||
Map<Enchantment, Material> enchMap = (Map<Enchantment, Material>) e.getKey();
|
Map<Enchantment, Material> enchMap = (Map<Enchantment, Material>) e.getKey();
|
||||||
enchAmounts.add(itemsEnchanted.get(enchMap));
|
enchAmounts.add(itemsEnchanted.get(enchMap));
|
||||||
for (Entry e2 : enchMap.entrySet()) {
|
for (Entry<Enchantment, Material> e2 : enchMap.entrySet()) {
|
||||||
|
|
||||||
enchantments.add(Quester.prettyEnchantmentString((Enchantment) e2.getKey()));
|
enchantments.add(Quester.prettyEnchantmentString((Enchantment) e2.getKey()));
|
||||||
itemIds.add(((Material) e2.getValue()).getId());
|
itemIds.add(((Material) e2.getValue()).getId());
|
||||||
@ -1847,7 +1849,7 @@ public class Quester {
|
|||||||
LinkedList<Integer> potionIds = new LinkedList<Integer>();
|
LinkedList<Integer> potionIds = new LinkedList<Integer>();
|
||||||
LinkedList<Integer> potionAmounts = new LinkedList<Integer>();
|
LinkedList<Integer> potionAmounts = new LinkedList<Integer>();
|
||||||
|
|
||||||
for (Entry entry : potionsBrewed.entrySet()) {
|
for (Entry<Integer, Integer> entry : potionsBrewed.entrySet()) {
|
||||||
|
|
||||||
potionIds.add((Integer) entry.getKey());
|
potionIds.add((Integer) entry.getKey());
|
||||||
potionAmounts.add((Integer) entry.getValue());
|
potionAmounts.add((Integer) entry.getValue());
|
||||||
|
@ -6,11 +6,14 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import me.blackvein.quests.util.ColorUtil;
|
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
|
|
||||||
import me.blackvein.quests.ItemData;
|
import me.blackvein.quests.ItemData;
|
||||||
import me.blackvein.quests.ItemData.Data;
|
|
||||||
import me.blackvein.quests.Quester;
|
import me.blackvein.quests.Quester;
|
||||||
import me.blackvein.quests.Quests;
|
import me.blackvein.quests.Quests;
|
||||||
|
import me.blackvein.quests.util.ColorUtil;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
@ -225,38 +228,38 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext cc, String input) {
|
public Prompt acceptInput(ConversationContext cc, String input) {
|
||||||
if(input.equalsIgnoreCase("cancel") == false){
|
if(input.equalsIgnoreCase("cancel") == false){
|
||||||
|
|
||||||
try{
|
String dataString = null;
|
||||||
Material mat = Material.getMaterial(Integer.parseInt(input));
|
if (input.contains(":")) {
|
||||||
if(mat == null){
|
String[] splitInput = input.split(":");
|
||||||
cc.getForWhom().sendRawMessage(RED + "Invalid item ID!");
|
input = splitInput[0];
|
||||||
return new IDPrompt();
|
if (splitInput.length > 1) {
|
||||||
}else{
|
dataString = splitInput[1];
|
||||||
cc.setSessionData("tempId", Integer.parseInt(input));
|
}
|
||||||
return new ItemStackPrompt(oldPrompt);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}catch(NumberFormatException e){
|
Material mat = ItemData.getMaterial(input);
|
||||||
try {
|
if(mat == null){
|
||||||
Data data = ItemData.getInstance().getItem(input);
|
cc.getForWhom().sendRawMessage(RED + "Invalid item ID!");
|
||||||
if (data == null) {
|
return new IDPrompt();
|
||||||
cc.getForWhom().sendRawMessage(RED + "Invalid item ID!");
|
} else {
|
||||||
return new IDPrompt();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
cc.setSessionData("tempId", data.getId());
|
cc.setSessionData("tempId", mat.getId());
|
||||||
cc.setSessionData("tempData", (data.getData() == 0) ? null : (short)data.getData());
|
|
||||||
return new ItemStackPrompt(oldPrompt);
|
|
||||||
}
|
|
||||||
} catch (Exception e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
cc.getForWhom().sendRawMessage(RED + "Invalid item ID!");
|
|
||||||
return new IDPrompt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
if (dataString != null) {
|
||||||
|
try {
|
||||||
|
short data = Short.parseShort(dataString);
|
||||||
|
cc.setSessionData("tempData", data);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
cc.getForWhom().sendRawMessage(RED + "Invalid item data!");
|
||||||
|
return new IDPrompt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ItemStackPrompt(oldPrompt);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
return new ItemStackPrompt(oldPrompt);
|
return new ItemStackPrompt(oldPrompt);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user