Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Custom Eggs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,20 @@ private void setupMobs() {
private void setupEgg() {
eggConfig.createDefaultSection("Eggs")
.setDefault("Regular.Name", "&7Regular Egg")
.setDefault("Regular.Material", "GHAST_SPAWN_EGG")
.setDefault("Regular.CustomModelData", 0)
.setDefault("Regular.Recipe", Arrays.asList("1:EGG", "5:IRON_INGOT"))
.setDefault("Regular.Cost", 0)
.setDefault("Regular.Chance", "25%")
.setDefault("Ultra.Name", "&6Ultra Egg")
.setDefault("Ultra.Material", "GHAST_SPAWN_EGG")
.setDefault("Ultra.CustomModelData", 0)
.setDefault("Ultra.Recipe", Arrays.asList("1:EGG", "5:DIAMOND"))
.setDefault("Ultra.Cost", 15)
.setDefault("Ultra.Chance", "60%")
.setDefault("Insane.Name", "&5Insane Egg")
.setDefault("Insane.Material", "GHAST_SPAWN_EGG")
.setDefault("Insane.CustomModelData", 0)
.setDefault("Insane.Recipe", Arrays.asList("1:EGG", "5:EMERALD"))
.setDefault("Insane.Cost", 50)
.setDefault("Insane.Chance", "100%");
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/com/songoda/ultimatecatcher/egg/CEgg.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatecatcher.UltimateCatcher;
import com.songoda.ultimatecatcher.settings.Settings;

import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

Expand All @@ -17,17 +18,19 @@ public class CEgg {

private final String key;
private String name;
private CompatibleMaterial material;
private List<String> recipe;
private double cost;
private int chance;
private int customModelData;

CEgg(String key) {
this.key = key;
}

public ItemStack toItemStack() {
ItemStack item = CompatibleMaterial.GHAST_SPAWN_EGG.getItem();

ItemStack item = material.getItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextUtils.formatText(name));

Expand All @@ -46,6 +49,9 @@ public ItemStack toItemStack() {
meta.setLore(lore);

item.setItemMeta(meta);

if(customModelData!=0)
meta.setCustomModelData(customModelData);

NBTItem nbtItem = new NBTItem(item);

Expand All @@ -58,6 +64,18 @@ public ItemStack toItemStack() {
public String getKey() {
return key;
}

public CompatibleMaterial getMaterial() {
return material;
}

public void setMaterial(String material) {
try {
this.material = CompatibleMaterial.valueOf(material);
}catch(IllegalArgumentException e) {
this.material = CompatibleMaterial.GHAST_SPAWN_EGG;
}
}

public String getName() {
return name;
Expand All @@ -66,6 +84,14 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

public int getCustomModelData() {
return customModelData;
}

public void setCustomModelData(int customModelData) {
this.customModelData = customModelData;;
}

public List<String> getRecipe() {
return recipe;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/songoda/ultimatecatcher/egg/EggBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public final class EggBuilder {
public EggBuilder(String key) {
this.egg = new CEgg(key);
}

public EggBuilder setMaterial(String name) {
this.egg.setMaterial(name);
return this;
}

public EggBuilder setName(String name) {
this.egg.setName(name);
Expand All @@ -29,6 +34,11 @@ public EggBuilder setChance(int chance) {
this.egg.setChance(chance);
return this;
}

public EggBuilder setCustomModelData(int customModelData) {
this.egg.setCustomModelData(customModelData);
return this;
}

public CEgg build() {
return egg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public void loadEggs() {

EggBuilder eggBuilder = new EggBuilder(keyName)
.setName(section.getString("Name"))
.setMaterial(section.getString("Material"))
.setRecipe(section.getStringList("Recipe"))
.setCost(section.getDouble("Cost"))
.setChance(Integer.parseInt(section.getString("Chance").replace("%", "")));
.setChance(Integer.parseInt(section.getString("Chance").replace("%", "")))
.setCustomModelData(Integer.parseInt(section.getString("CustomModelData")));

addEgg(eggBuilder.build());
}
Expand Down