Skip to content

Instantly share code, notes, and snippets.

@ralmn
Created June 25, 2013 17:13
Show Gist options
  • Save ralmn/5860336 to your computer and use it in GitHub Desktop.
Save ralmn/5860336 to your computer and use it in GitHub Desktop.
package fr.ralmn.rush.object;
import net.minecraft.server.v1_5_R3.EntityVillager;
import net.minecraft.server.v1_5_R3.MerchantRecipe;
import net.minecraft.server.v1_5_R3.MerchantRecipeList;
import net.minecraft.server.v1_5_R3.NBTTagCompound;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_5_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import java.awt.*;
import java.awt.Color;
import java.util.ArrayList;
/**
* Created with IntelliJ IDEA.
* User: ralmn
* Date: 25/06/13
* Time: 16:13
* To change this template use File | Settings | File Templates.
*/
public class Villager {
private Location location;
private int typeId;
private String color;
public Villager(Location location, int typeId, String color) {
this.location = location;
this.typeId = typeId;
this.color = color;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public EntityVillager createVilager(){
CraftWorld cw = (CraftWorld) location.getWorld();
EntityVillager ev = new EntityVillager(cw.getHandle());
ev.setHealth(50000000);
ev.setLocation(location.getX(), location.getY(), location.getBlockZ(), location.getPitch(), location.getYaw());
MerchantRecipeList offers = ev.getOffers(null);
NBTTagCompound ntb = new NBTTagCompound();
if(typeId == 1){
offers = offersone(offers);
ev.setProfession(5);
ntb.setInt("Profession", 5);
}else if(typeId == 2){
offers = offerstwo(offers);
ev.setProfession(0);
ntb.setInt("Profession", 0);
} else if(typeId == 3){
offers = offersthird(offers);
ev.setProfession(1);
ntb.setInt("Profession", 1);
}else if(typeId == 4){
String c = "#496ACC";
if(color.equalsIgnoreCase("red")){
c = "#F1B232";
}
offers = offersfour(offers, c);
ev.setProfession(2);
ntb.setInt("Profession", 2);
}
ntb.setCompound("Offers", offers.a());
ev.a(ntb);
return ev;
}
private static MerchantRecipeList offersone(MerchantRecipeList offers){
offers.clear();
ItemStack r1b1 = new ItemStack(Spawner.gold());
r1b1.setAmount(3);
ItemStack r1s = new ItemStack(Material.BOW, 1);
ItemMeta r1sm = r1s.getItemMeta();
r1sm.setDisplayName(ChatColor.GREEN + "Bow");
r1sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
ArrayList<String> lore = new ArrayList<String>();
lore.add("Level 1");
r1sm.setLore(lore);
r1s.setItemMeta(r1sm);
net.minecraft.server.v1_5_R3.ItemStack r1s_s = CraftItemStack.asNMSCopy(r1s);
net.minecraft.server.v1_5_R3.ItemStack r1b1_s = CraftItemStack.asNMSCopy(r1b1);
MerchantRecipe r1 = new MerchantRecipe(r1b1_s, r1s_s);
r1.a(5000000);
offers.add(r1);
ItemStack r2b1 = new ItemStack(Spawner.gold());
r2b1.setAmount(7);
ItemStack r2s = new ItemStack(Material.BOW, 1);
ItemMeta r2sm = r1s.getItemMeta();
r2sm.setDisplayName(ChatColor.GREEN + "Bow");
r2sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r2sm.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
lore = new ArrayList<String>();
lore.add("Level 2");
r2sm.setLore(lore);
r2s.setItemMeta(r2sm);
net.minecraft.server.v1_5_R3.ItemStack r2s_s = CraftItemStack.asNMSCopy(r2s);
net.minecraft.server.v1_5_R3.ItemStack r2b1_s = CraftItemStack.asNMSCopy(r2b1);
MerchantRecipe r2 = new MerchantRecipe(r2b1_s, r2s_s);
r2.a(5000000);
offers.add(r2);
ItemStack r3b1 = new ItemStack(Spawner.gold());
r3b1.setAmount(13);
ItemStack r3s = new ItemStack(Material.BOW, 1);
ItemMeta r3sm = r1s.getItemMeta();
r3sm.setDisplayName(ChatColor.GREEN + "Bow");
r3sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r3sm.addEnchant(Enchantment.ARROW_DAMAGE, 2, true);
lore = new ArrayList<String>();
lore.add("Level 3");
r3sm.setLore(lore);
r3s.setItemMeta(r3sm);
net.minecraft.server.v1_5_R3.ItemStack r3s_s = CraftItemStack.asNMSCopy(r3s);
net.minecraft.server.v1_5_R3.ItemStack r3b1_s = CraftItemStack.asNMSCopy(r3b1);
MerchantRecipe r3 = new MerchantRecipe(r3b1_s, r3s_s);
r3.a(5000000);
offers.add(r3);
ItemStack r4b1 = Spawner.gold().clone();
r4b1.setAmount(1);
ItemStack r4s = new ItemStack(Material.ARROW, 1);
net.minecraft.server.v1_5_R3.ItemStack r4s_s = CraftItemStack.asNMSCopy(r4s);
net.minecraft.server.v1_5_R3.ItemStack r4b1_s = CraftItemStack.asNMSCopy(r4b1);
MerchantRecipe r4 = new MerchantRecipe(r4b1_s, r4s_s);
r4.a(5000000);
offers.add(r4);
ItemStack r5b1 = Spawner.bronze().clone();
r5b1.setAmount(2);
ItemStack r5s = new ItemStack(Material.COOKED_BEEF, 2);
net.minecraft.server.v1_5_R3.ItemStack r5s_s = CraftItemStack.asNMSCopy(r5s);
net.minecraft.server.v1_5_R3.ItemStack r5b1_s = CraftItemStack.asNMSCopy(r5b1);
MerchantRecipe r5 = new MerchantRecipe(r5b1_s, r5s_s);
r5.a(5000000);
offers.add(r5);
ItemStack r6b1 = Spawner.silver().clone();
r6b1.setAmount(1);
ItemStack r6s = new ItemStack(Material.GOLDEN_APPLE, 1);
net.minecraft.server.v1_5_R3.ItemStack r6s_s = CraftItemStack.asNMSCopy(r6s);
net.minecraft.server.v1_5_R3.ItemStack r6b1_s = CraftItemStack.asNMSCopy(r6b1);
MerchantRecipe r6 = new MerchantRecipe(r6b1_s, r6s_s);
r6.a(5000000);
offers.add(r6);
return offers;
}
private static MerchantRecipeList offerstwo(MerchantRecipeList offers){
offers.clear();
ItemStack r1b1 = new ItemStack(Spawner.gold());
r1b1.setAmount(1);
ItemStack r1s = new ItemStack(Material.BOW, 1);
ItemMeta r1sm = r1s.getItemMeta();
r1sm.setDisplayName(ChatColor.GREEN + "Bow");
r1sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r1sm.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
ArrayList<String> lore = new ArrayList<String>();
lore.add("Level 1");
r1sm.setLore(lore);
r1s.setItemMeta(r1sm);
net.minecraft.server.v1_5_R3.ItemStack r1s_s = CraftItemStack.asNMSCopy(r1s);
net.minecraft.server.v1_5_R3.ItemStack r1b1_s = CraftItemStack.asNMSCopy(r1b1);
MerchantRecipe r1 = new MerchantRecipe(r1b1_s, r1s_s);
r1.a(5000000);
offers.add(r1);
ItemStack r2b1 = new ItemStack(Spawner.gold());
r2b1.setAmount(3);
ItemStack r2s = new ItemStack(Material.BOW, 1);
ItemMeta r2sm = r1s.getItemMeta();
r2sm.setDisplayName(ChatColor.RED + "Sword");
r2sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r2sm.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
lore = new ArrayList<String>();
lore.add("Level 2");
r2sm.setLore(lore);
r2s.setItemMeta(r2sm);
net.minecraft.server.v1_5_R3.ItemStack r2s_s = CraftItemStack.asNMSCopy(r2s);
net.minecraft.server.v1_5_R3.ItemStack r2b1_s = CraftItemStack.asNMSCopy(r2b1);
MerchantRecipe r2 = new MerchantRecipe(r2b1_s, r2s_s);
r2.a(5000000);
offers.add(r2);
ItemStack r3b1 = new ItemStack(Spawner.gold());
r3b1.setAmount(7);
ItemStack r3s = new ItemStack(Material.BOW, 1);
ItemMeta r3sm = r1s.getItemMeta();
r3sm.setDisplayName(ChatColor.RED + "Sword");
r3sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r3sm.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
r3sm.addEnchant(Enchantment.KNOCKBACK, 1, true);
lore = new ArrayList<String>();
lore.add("Level 3");
r3sm.setLore(lore);
r3s.setItemMeta(r3sm);
net.minecraft.server.v1_5_R3.ItemStack r3s_s = CraftItemStack.asNMSCopy(r3s);
net.minecraft.server.v1_5_R3.ItemStack r3b1_s = CraftItemStack.asNMSCopy(r3b1);
MerchantRecipe r3 = new MerchantRecipe(r3b1_s, r3s_s);
r3.a(5000000);
offers.add(r3);
ItemStack r4b1 = Spawner.silver().clone();
r4b1.setAmount(3);
ItemStack r4s = new ItemStack(Material.TNT, 1);
net.minecraft.server.v1_5_R3.ItemStack r4s_s = CraftItemStack.asNMSCopy(r4s);
net.minecraft.server.v1_5_R3.ItemStack r4b1_s = CraftItemStack.asNMSCopy(r4b1);
MerchantRecipe r4 = new MerchantRecipe(r4b1_s, r4s_s);
r4.a(5000000);
offers.add(r4);
ItemStack r5b1 = Spawner.gold().clone();
r5b1.setAmount(1);
ItemStack r5s = new ItemStack(Material.FLINT_AND_STEEL, 1);
net.minecraft.server.v1_5_R3.ItemStack r5s_s = CraftItemStack.asNMSCopy(r5s);
net.minecraft.server.v1_5_R3.ItemStack r5b1_s = CraftItemStack.asNMSCopy(r5b1);
MerchantRecipe r5 = new MerchantRecipe(r5b1_s, r5s_s);
r5.a(5000000);
offers.add(r5);
ItemStack r6b1 = Spawner.silver().clone();
r6b1.setAmount(1);
ItemStack r6s = new ItemStack(Material.CHEST, 1);
net.minecraft.server.v1_5_R3.ItemStack r6s_s = CraftItemStack.asNMSCopy(r6s);
net.minecraft.server.v1_5_R3.ItemStack r6b1_s = CraftItemStack.asNMSCopy(r6b1);
MerchantRecipe r6 = new MerchantRecipe(r6b1_s, r6s_s);
r6.a(5000000);
offers.add(r6);
return offers;
}
private static MerchantRecipeList offersthird(MerchantRecipeList offers){
offers.clear();
ItemStack r1b1 = new ItemStack(Spawner.bronze());
r1b1.setAmount(1);
ItemStack r1s = new ItemStack(Material.SANDSTONE, 1);
r1s.setDurability((short) 2);
net.minecraft.server.v1_5_R3.ItemStack r1s_s = CraftItemStack.asNMSCopy(r1s);
net.minecraft.server.v1_5_R3.ItemStack r1b1_s = CraftItemStack.asNMSCopy(r1b1);
MerchantRecipe r1 = new MerchantRecipe(r1b1_s, r1s_s);
r1.a(5000000);
offers.add(r1);
ItemStack r2b1 = new ItemStack(Spawner.bronze());
r2b1.setAmount(4);
ItemStack r2s = new ItemStack(Material.GLOWSTONE, 2);
net.minecraft.server.v1_5_R3.ItemStack r2s_s = CraftItemStack.asNMSCopy(r2s);
net.minecraft.server.v1_5_R3.ItemStack r2b1_s = CraftItemStack.asNMSCopy(r2b1);
MerchantRecipe r2 = new MerchantRecipe(r2b1_s, r2s_s);
r2.a(5000000);
offers.add(r2);
ItemStack r3b1 = new ItemStack(Spawner.bronze());
r3b1.setAmount(4);
ItemStack r3s = new ItemStack(Material.ENDER_STONE, 1);
net.minecraft.server.v1_5_R3.ItemStack r3s_s = CraftItemStack.asNMSCopy(r3s);
net.minecraft.server.v1_5_R3.ItemStack r3b1_s = CraftItemStack.asNMSCopy(r3b1);
MerchantRecipe r3 = new MerchantRecipe(r3b1_s, r3s_s);
r3.a(5000000);
offers.add(r3);
ItemStack r4b1 = Spawner.bronze().clone();
r4b1.setAmount(4);
ItemStack r4s = new ItemStack(Material.WOOD_PICKAXE, 1);
ItemMeta r4sm = r4s.getItemMeta();
r4sm.setDisplayName(ChatColor.DARK_PURPLE + "Pickaxe");
r4sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r4sm.addEnchant(Enchantment.DIG_SPEED, 1, true);
ArrayList<String> lore = new ArrayList<String>();
lore.add("Level 1");
r4sm.setLore(lore);
r4s.setItemMeta(r4sm);
net.minecraft.server.v1_5_R3.ItemStack r4s_s = CraftItemStack.asNMSCopy(r4s);
net.minecraft.server.v1_5_R3.ItemStack r4b1_s = CraftItemStack.asNMSCopy(r4b1);
MerchantRecipe r4 = new MerchantRecipe(r4b1_s, r4s_s);
r4.a(5000000);
offers.add(r4);
ItemStack r5b1 = Spawner.gold().clone();
r5b1.setAmount(1);
ItemStack r5s = new ItemStack(Material.STONE_PICKAXE, 1);
ItemMeta r5sm = r5s.getItemMeta();
r5sm.setDisplayName(ChatColor.DARK_PURPLE + "Pickaxe");
r5sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r5sm.addEnchant(Enchantment.DIG_SPEED, 2, true);
lore = new ArrayList<String>();
lore.add("Level 2");
r5sm.setLore(lore);
r5s.setItemMeta(r5sm);
net.minecraft.server.v1_5_R3.ItemStack r5s_s = CraftItemStack.asNMSCopy(r5s);
net.minecraft.server.v1_5_R3.ItemStack r5b1_s = CraftItemStack.asNMSCopy(r5b1);
MerchantRecipe r5 = new MerchantRecipe(r5b1_s, r5s_s);
r5.a(5000000);
offers.add(r5);
ItemStack r6b1 = Spawner.silver().clone();
r6b1.setAmount(1);
ItemStack r6s = new ItemStack(Material.IRON_PICKAXE, 1);
ItemMeta r6sm = r6s.getItemMeta();
r6sm.setDisplayName(ChatColor.DARK_PURPLE + "Pickaxe");
r6sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r6sm.addEnchant(Enchantment.DIG_SPEED, 3, true);
lore = new ArrayList<String>();
lore.add("Level 3");
r6sm.setLore(lore);
r6s.setItemMeta(r6sm);
net.minecraft.server.v1_5_R3.ItemStack r6s_s = CraftItemStack.asNMSCopy(r6s);
net.minecraft.server.v1_5_R3.ItemStack r6b1_s = CraftItemStack.asNMSCopy(r6b1);
MerchantRecipe r6 = new MerchantRecipe(r6b1_s, r6s_s);
r6.a(5000000);
offers.add(r6);
return offers;
}
private static MerchantRecipeList offersfour(MerchantRecipeList offers, String color){
offers.clear();
ItemStack r1b1 = new ItemStack(Spawner.bronze());
r1b1.setAmount(1);
ItemStack r1s = new ItemStack(Material.LEATHER_HELMET, 1);
LeatherArmorMeta r1sm = (LeatherArmorMeta) r1s.getItemMeta();
r1sm.setDisplayName(ChatColor.BLUE + "Armor");
r1sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
r1sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
int r = Color.decode(color).getRed();
int g = Color.decode(color).getGreen();
int b = Color.decode(color).getBlue();
r1sm.setColor(org.bukkit.Color.fromRGB(r,g,b));
r1s.setItemMeta(r1sm);
net.minecraft.server.v1_5_R3.ItemStack r1s_s = CraftItemStack.asNMSCopy(r1s);
net.minecraft.server.v1_5_R3.ItemStack r1b1_s = CraftItemStack.asNMSCopy(r1b1);
MerchantRecipe r1 = new MerchantRecipe(r1b1_s, r1s_s);
r1.a(5000000);
offers.add(r1);
ItemStack r2b1 = new ItemStack(Spawner.bronze());
r2b1.setAmount(1);
ItemStack r2s = new ItemStack(Material.LEATHER_LEGGINGS, 1);
LeatherArmorMeta r2sm = (LeatherArmorMeta) r2s.getItemMeta();
r2sm.setDisplayName(ChatColor.BLUE + "Armor");
r2sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
r2sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r = Color.decode(color).getRed();
g = Color.decode(color).getGreen();
b = Color.decode(color).getBlue();
r2sm.setColor(org.bukkit.Color.fromRGB(r, g, b));
r2s.setItemMeta(r2sm);
net.minecraft.server.v1_5_R3.ItemStack r2s_s = CraftItemStack.asNMSCopy(r2s);
net.minecraft.server.v1_5_R3.ItemStack r2b1_s = CraftItemStack.asNMSCopy(r2b1);
MerchantRecipe r2 = new MerchantRecipe(r2b1_s, r2s_s);
r2.a(5000000);
offers.add(r2);
ItemStack r3b1 = new ItemStack(Spawner.bronze());
r3b1.setAmount(1);
ItemStack r3s = new ItemStack(Material.LEATHER_BOOTS, 1);
LeatherArmorMeta r3sm = (LeatherArmorMeta) r3s.getItemMeta();
r3sm.setDisplayName(ChatColor.BLUE + "Armor");
r3sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
r3sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r = Color.decode(color).getRed();
g = Color.decode(color).getGreen();
b = Color.decode(color).getBlue();
r3sm.setColor(org.bukkit.Color.fromRGB(r, g, b));
r3s.setItemMeta(r3sm);
net.minecraft.server.v1_5_R3.ItemStack r3s_s = CraftItemStack.asNMSCopy(r3s);
net.minecraft.server.v1_5_R3.ItemStack r3b1_s = CraftItemStack.asNMSCopy(r3b1);
MerchantRecipe r3 = new MerchantRecipe(r3b1_s, r3s_s);
r3.a(5000000);
offers.add(r3);
ItemStack r4b1 = Spawner.silver().clone();
r4b1.setAmount(1);
ItemStack r4s = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
ItemMeta r4sm = r4s.getItemMeta();
r4sm.setDisplayName(ChatColor.YELLOW + "Chestplate");
r4sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r4sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
ArrayList<String> lore = new ArrayList<String>();
lore.add("Level 1");
r4sm.setLore(lore);
r4s.setItemMeta(r4sm);
net.minecraft.server.v1_5_R3.ItemStack r4s_s = CraftItemStack.asNMSCopy(r4s);
net.minecraft.server.v1_5_R3.ItemStack r4b1_s = CraftItemStack.asNMSCopy(r4b1);
MerchantRecipe r4 = new MerchantRecipe(r4b1_s, r4s_s);
r4.a(5000000);
offers.add(r4);
ItemStack r5b1 = Spawner.silver().clone();
r5b1.setAmount(3);
ItemStack r5s = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
ItemMeta r5sm = r5s.getItemMeta();
r5sm.setDisplayName(ChatColor.YELLOW + "Chestplate");
r5sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r5sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true);
lore = new ArrayList<String>();
lore.add("Level 2");
r5sm.setLore(lore);
r5s.setItemMeta(r5sm);
net.minecraft.server.v1_5_R3.ItemStack r5s_s = CraftItemStack.asNMSCopy(r5s);
net.minecraft.server.v1_5_R3.ItemStack r5b1_s = CraftItemStack.asNMSCopy(r5b1);
MerchantRecipe r5 = new MerchantRecipe(r5b1_s, r5s_s);
r5.a(5000000);
offers.add(r5);
ItemStack r6b1 = Spawner.silver().clone();
r6b1.setAmount(7);
ItemStack r6s = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
ItemMeta r6sm = r6s.getItemMeta();
r6sm.setDisplayName(ChatColor.YELLOW + "Chestplate");
r6sm.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
r6sm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
lore = new ArrayList<String>();
lore.add("Level 3");
r6sm.setLore(lore);
r6s.setItemMeta(r6sm);
net.minecraft.server.v1_5_R3.ItemStack r6s_s = CraftItemStack.asNMSCopy(r6s);
net.minecraft.server.v1_5_R3.ItemStack r6b1_s = CraftItemStack.asNMSCopy(r6b1);
MerchantRecipe r6 = new MerchantRecipe(r6b1_s, r6s_s);
r6.a(5000000);
offers.add(r6);
return offers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment