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