diff --git a/.classpath b/.classpath index 8355594..f1ed9f2 100644 --- a/.classpath +++ b/.classpath @@ -3,6 +3,6 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index bb35fa0..980b98c 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/src/de/Ste3et_C0st/Furniture/Listener/OnInteract.java b/src/de/Ste3et_C0st/Furniture/Listener/OnInteract.java index 55a7bf9..a91d060 100644 --- a/src/de/Ste3et_C0st/Furniture/Listener/OnInteract.java +++ b/src/de/Ste3et_C0st/Furniture/Listener/OnInteract.java @@ -3,7 +3,6 @@ package de.Ste3et_C0st.Furniture.Listener; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -13,11 +12,12 @@ import org.bukkit.inventory.ItemStack; import de.Ste3et_C0st.Furniture.Main.Utils; import de.Ste3et_C0st.Furniture.Main.main; -import de.Ste3et_C0st.Furniture.Objects.largeTable; -import de.Ste3et_C0st.Furniture.Objects.laterne; -import de.Ste3et_C0st.Furniture.Objects.sofa; -import de.Ste3et_C0st.Furniture.Objects.stuhl; -import de.Ste3et_C0st.Furniture.Objects.tisch; +import de.Ste3et_C0st.Furniture.Objects.indoor.chair; +import de.Ste3et_C0st.Furniture.Objects.indoor.largeTable; +import de.Ste3et_C0st.Furniture.Objects.indoor.latern; +import de.Ste3et_C0st.Furniture.Objects.indoor.sofa; +import de.Ste3et_C0st.Furniture.Objects.indoor.table; +import de.Ste3et_C0st.Furniture.Objects.outdoor.tent_1; public class OnInteract implements Listener { @@ -26,55 +26,37 @@ public class OnInteract implements Listener { Player p = e.getPlayer(); if(e.getItem() == null){return;} if(e.getClickedBlock() == null){return;} - ItemStack is = e.getItem(); - if(!is.hasItemMeta()){return;} - if(!is.getType().equals(Material.MONSTER_EGG)){return;} - if(!is.getItemMeta().hasDisplayName()){return;} if(e.getClickedBlock()==null){return;} if(!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){return;} + ItemStack is = e.getItem(); + if(!(is!=null&&is.hasItemMeta()&&is.getItemMeta().hasDisplayName())){return;} + Integer hand = p.getInventory().getHeldItemSlot(); Integer amount = is.getAmount(); Location location = new Location(p.getWorld(), e.getClickedBlock().getLocation().getBlockX(), e.getClickedBlock().getLocation().getBlockY(), e.getClickedBlock().getLocation().getBlockZ()); location.setYaw(p.getLocation().getYaw()); location.setY(location.getY() + 1); - if(ChatColor.stripColor(is.getItemMeta().getDisplayName()).equalsIgnoreCase("sofa")){ + ItemStack saveIS = getItemStackCopy(is); + String noPermissions = ChatColor.translateAlternateColorCodes('&', main.getInstance().getConfig().getString("config.Messages.NoPermissions")); + if(saveIS.equals(main.getInstance().crafting.get("sofa"))){ + if(!p.hasPermission("furniture.sofa")){p.sendMessage(noPermissions);return;} if(main.getInstance().canPlace(p, location, Utils.yawToFace(location.getYaw()).getOppositeFace(), 3)){ - new sofa(location, 3, main.getInstance()); + new sofa(location, 3, main.getInstance(), null, main.createRandomRegistryId()); if(!p.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(amount); + is.setAmount(amount-1); p.getInventory().setItem(hand, is); p.updateInventory(); } return; } } - if(ChatColor.stripColor(is.getItemMeta().getDisplayName()).equalsIgnoreCase("laterne")){ + + if(saveIS.equals(main.getInstance().crafting.get("lantern"))){ + if(!p.hasPermission("furniture.lantern")){p.sendMessage(noPermissions);return;} if(main.getInstance().canPlace(p, location, null, null)){ - new laterne(location, main.getInstance(), true); + new latern(location, main.getInstance(), true, main.createRandomRegistryId()); if(!p.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(amount); - p.getInventory().setItem(hand, is); - p.updateInventory(); - } - return; - } - } - if(ChatColor.stripColor(is.getItemMeta().getDisplayName()).equalsIgnoreCase("stuhl")){ - if(main.getInstance().canPlace(p, location, null, null)){ - new stuhl(location, main.getInstance()); - if(!p.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(amount); - p.getInventory().setItem(hand, is); - p.updateInventory(); - } - return; - } - } - if(ChatColor.stripColor(is.getItemMeta().getDisplayName()).equalsIgnoreCase("tisch")){ - if(main.getInstance().canPlace(p, location, null, null)){ - new tisch(location, main.getInstance(), null); - if(!p.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(amount); + is.setAmount(amount-1); p.getInventory().setItem(hand, is); p.updateInventory(); } @@ -82,11 +64,51 @@ public class OnInteract implements Listener { } } - if(ChatColor.stripColor(is.getItemMeta().getDisplayName()).equalsIgnoreCase("tisch2")){ + if(saveIS.equals(main.getInstance().crafting.get("chair"))){ + if(!p.hasPermission("furniture.chair")){p.sendMessage(noPermissions);return;} if(main.getInstance().canPlace(p, location, null, null)){ - new largeTable(location, main.getInstance(), null, null); + new chair(location, main.getInstance(), main.createRandomRegistryId()); if(!p.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(amount); + is.setAmount(amount-1); + p.getInventory().setItem(hand, is); + p.updateInventory(); + } + return; + } + } + + if(saveIS.equals(main.getInstance().crafting.get("table"))){ + if(!p.hasPermission("furniture.table")){p.sendMessage(noPermissions);return;} + if(main.getInstance().canPlace(p, location, null, null)){ + new table(location, main.getInstance(), null, main.createRandomRegistryId()); + if(!p.getGameMode().equals(GameMode.CREATIVE)){ + is.setAmount(amount-1); + p.getInventory().setItem(hand, is); + p.updateInventory(); + } + return; + } + } + + if(saveIS.equals(main.getInstance().crafting.get("largeTable"))){ + if(!p.hasPermission("furniture.largetable")){p.sendMessage(noPermissions);return;} + if(main.getInstance().canPlaceLarge(p, location, Utils.yawToFace(location.getYaw()).getOppositeFace(), 3,3)){ + new largeTable(location, main.getInstance(), null, null, main.createRandomRegistryId()); + if(!p.getGameMode().equals(GameMode.CREATIVE)){ + is.setAmount(amount-1); + p.getInventory().setItem(hand, is); + p.updateInventory(); + } + return; + } + } + + if(saveIS.equals(main.getInstance().crafting.get("tent1"))){ + if(!p.hasPermission("furniture.tent1")){p.sendMessage(noPermissions);return;} + if(main.getInstance().canPlaceTent(p, location, Utils.yawToFace(location.getYaw()).getOppositeFace(), 5,4, 3)){ + new tent_1(location, main.getInstance(), main.createRandomRegistryId()); + if(!p.getGameMode().equals(GameMode.CREATIVE)){ + is.setAmount(amount-1); p.getInventory().setItem(hand, is); p.updateInventory(); } @@ -94,4 +116,12 @@ public class OnInteract implements Listener { } } } + + public ItemStack getItemStackCopy(ItemStack is){ + ItemStack copy = new ItemStack(is.getType()); + copy.setAmount(1); + copy.setDurability(is.getDurability()); + copy.setItemMeta(is.getItemMeta()); + return copy; + } } diff --git a/src/de/Ste3et_C0st/Furniture/Main/ItemsEquipment.java b/src/de/Ste3et_C0st/Furniture/Main/ItemsEquipment.java deleted file mode 100644 index e300049..0000000 --- a/src/de/Ste3et_C0st/Furniture/Main/ItemsEquipment.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.Ste3et_C0st.Furniture.Main; - -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -public class ItemsEquipment { - - public ItemStack Laterne = null; - public ItemStack Sofa = null; - public ItemStack stuhl = null; - public ItemStack tisch = null; - public ItemStack tisch2 = null; - public ItemsEquipment(){ - ItemMeta im = null; - this.Sofa = new ItemStack(Material.MONSTER_EGG); - im = this.Sofa.getItemMeta(); - im.addEnchant(Enchantment.ARROW_INFINITE, 1, true); - im.setDisplayName("§cSofa"); - this.Sofa.setItemMeta(im); - - this.Laterne = new ItemStack(Material.MONSTER_EGG); - im = this.Laterne.getItemMeta(); - im.addEnchant(Enchantment.ARROW_INFINITE, 1, true); - im.setDisplayName("§cLaterne"); - this.Laterne.setItemMeta(im); - - this.stuhl = new ItemStack(Material.MONSTER_EGG); - im = this.stuhl.getItemMeta(); - im.addEnchant(Enchantment.ARROW_INFINITE, 1, true); - im.setDisplayName("§cStuhl"); - this.stuhl.setItemMeta(im); - - this.tisch = new ItemStack(Material.MONSTER_EGG); - im = this.tisch.getItemMeta(); - im.addEnchant(Enchantment.ARROW_INFINITE, 1, true); - im.setDisplayName("§cTisch"); - this.tisch.setItemMeta(im); - - this.tisch2 = new ItemStack(Material.MONSTER_EGG); - im = this.tisch2.getItemMeta(); - im.addEnchant(Enchantment.ARROW_INFINITE, 1, true); - im.setDisplayName("§cTisch2"); - this.tisch2.setItemMeta(im); - } -} diff --git a/src/de/Ste3et_C0st/Furniture/Main/Manager.java b/src/de/Ste3et_C0st/Furniture/Main/Manager.java index 882fa7e..d57e2c6 100644 --- a/src/de/Ste3et_C0st/Furniture/Main/Manager.java +++ b/src/de/Ste3et_C0st/Furniture/Main/Manager.java @@ -1,28 +1,35 @@ package de.Ste3et_C0st.Furniture.Main; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; -import de.Ste3et_C0st.DiceEaster.config; -import de.Ste3et_C0st.Furniture.Objects.laterne; -import de.Ste3et_C0st.Furniture.Objects.stuhl; -import de.Ste3et_C0st.Furniture.Objects.tisch; +import de.Ste3et_C0st.Furniture.Main.config; +import de.Ste3et_C0st.Furniture.Objects.indoor.chair; +import de.Ste3et_C0st.Furniture.Objects.indoor.largeTable; +import de.Ste3et_C0st.Furniture.Objects.indoor.latern; +import de.Ste3et_C0st.Furniture.Objects.indoor.sofa; +import de.Ste3et_C0st.Furniture.Objects.indoor.table; +import de.Ste3et_C0st.Furniture.Objects.outdoor.tent_1; public class Manager { private static config cc; private static FileConfiguration fc; - private String folder = "/furniture/"; + private String folder = "/objects/"; public void loadStuhl(){ cc = new config(); @@ -34,14 +41,15 @@ public class Manager { path+= "." + s; Double x = fc.getDouble(path+".Location.x"); - Double y = fc.getDouble(path+".Location.x"); - Double z = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); World w = Bukkit.getWorld(fc.getString(path+".Location.w")); - Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw")); + String face = fc.getString(path+".Location.face"); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); Location l = new Location(w, x, y, z); l.setYaw(yaw); - new stuhl(l, main.getInstance()); + new chair(l, main.getInstance(), s); } } } @@ -49,28 +57,28 @@ public class Manager { public void loadLatern(){ cc = new config(); - if(cc.ExistConfig(folder, "latern.yml")){ - fc = cc.getConfig("latern.yml", folder); - if(fc.isSet("Furniture.latern")){ - for(String s : fc.getConfigurationSection("Furniture.latern").getKeys(false)){ - String path = "Furniture.latern"; + if(cc.ExistConfig(folder, "lantern.yml")){ + fc = cc.getConfig("lantern.yml", folder); + if(fc.isSet("Furniture.lantern")){ + for(String s : fc.getConfigurationSection("Furniture.lantern").getKeys(false)){ + String path = "Furniture.lantern"; path+= "." + s; Double x = fc.getDouble(path+".Location.x"); - Double y = fc.getDouble(path+".Location.x"); - Double z = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); World w = Bukkit.getWorld(fc.getString(path+".Location.w")); - Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw")); + String face = fc.getString(path+".Location.face"); Boolean b = fc.getBoolean(path+".settings.Light"); Location l = new Location(w, x, y, z); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); l.setYaw(yaw); - new laterne(l, main.getInstance(), b); + new latern(l, main.getInstance(), b, s); } } } } - @SuppressWarnings("deprecation") public void loadTisch(){ cc = new config(); if(cc.ExistConfig(folder, "table.yml")){ @@ -81,47 +89,404 @@ public class Manager { path+= "." + s; Double x = fc.getDouble(path+".Location.x"); - Double y = fc.getDouble(path+".Location.x"); - Double z = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); World w = Bukkit.getWorld(fc.getString(path+".Location.w")); - Float yaw = (float) fc.getInt(fc.getString(path+".Location.Yaw")); + String face = fc.getString(path+".Location.face"); Location l = new Location(w, x, y, z); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); l.setYaw(yaw); - ItemStack is = null; - if(fc.isSet(path+".settings.ItemStack")){ - Material m = Material.getMaterial(fc.getInt(path+".settings.ItemStack.Material")); - Short subID = (short) fc.getInt(path+".settings.ItemStack.Durability"); - Integer amount = fc.getInt(path+".settings.ItemStack.Amount"); - is = new ItemStack(m,amount,subID); - ItemMeta im = is.getItemMeta(); - - List lore = new ArrayList(); - if(fc.isSet(path+".settings.ItemStack.Lore")){ - lore = fc.getStringList(path+".settings.ItemStack.Lore"); - im.setLore(lore); - } - - if(fc.isSet(path+".settings.ItemStack.Enchantment")){ - for(String enchant : fc.getConfigurationSection(path+".settings.ItemStack.Enchantment").getKeys(false)){ - Enchantment en = Enchantment.getByName(enchant); - im.addEnchant(en, fc.getInt(path+".settings.ItemStack.Enchantment." + enchant + ".id"), true); - } - } - is.setItemMeta(im); - if(is.getItemMeta() instanceof LeatherArmorMeta){ - LeatherArmorMeta lim = (LeatherArmorMeta) is.getItemMeta(); - if(fc.isSet(path+".settings.ItemStack.LeatherMeta")){ - lim.setColor(Color.fromBGR( - fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.blue"), - fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.green"), - fc.getInt(path+".settings.ItemStack.LeatherMeta.Color.red"))); - } - is.setItemMeta(lim); - } - } - new tisch(l, main.getInstance(), is); + ItemStack is = getItemStack(fc, path+".settings.ItemStack"); + new table(l, main.getInstance(), is, s); } } } } + + @SuppressWarnings("deprecation") + public ItemStack getItemStack(FileConfiguration fc, String s){ + String path = s; + ItemStack is = null; + if(fc.isSet(path)){ + Material m = Material.getMaterial(fc.getInt(path+".material")); + Short subID = (short) fc.getInt(path+".durability"); + Integer amount = fc.getInt(path+".amount"); + is = new ItemStack(m,amount,subID); + ItemMeta im = is.getItemMeta(); + + List lore = new ArrayList(); + if(fc.isSet(path+".lore")){ + lore = fc.getStringList(path+".lore"); + im.setLore(lore); + } + + if(fc.isSet(path+".displayName")){ + im.setDisplayName(fc.getString(path+".displayName")); + } + + if(fc.isSet(path+".Enchantment")){ + for(String enchant : fc.getConfigurationSection(path+".Enchantment").getKeys(false)){ + Enchantment en = Enchantment.getByName(enchant); + im.addEnchant(en, fc.getInt(path+".Enchantment." + enchant + ".lvl"), true); + } + } + is.setItemMeta(im); + if(is.getItemMeta() instanceof LeatherArmorMeta){ + LeatherArmorMeta lim = (LeatherArmorMeta) is.getItemMeta(); + if(fc.isSet(path+".LeatherMeta")){ + lim.setColor(Color.fromBGR( + fc.getInt(path+".LeatherMeta.Color.blue"), + fc.getInt(path+".LeatherMeta.Color.green"), + fc.getInt(path+".LeatherMeta.Color.red"))); + } + is.setItemMeta(lim); + } + } + return is; + } + + public List getList(FileConfiguration fc, String s){ + List itemlist = new ArrayList(); + if(fc.isSet(s)){ + for(String string : fc.getConfigurationSection(s).getKeys(false)){ + ItemStack is = new ItemStack(Material.getMaterial(fc.getString(s+"."+string+".material"))); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(main.createRandomRegistryId()); + is.setDurability((short) fc.getInt(s+"."+string+".durability")); + is.setItemMeta(im); + itemlist.add(is); + } + } + return itemlist; + } + + public void loadLargeTisch(){ + cc = new config(); + if(cc.ExistConfig(folder, "largeTable.yml")){ + fc = cc.getConfig("largeTable.yml", folder); + if(fc.isSet("Furniture.largeTable")){ + for(String s : fc.getConfigurationSection("Furniture.largeTable").getKeys(false)){ + String path = "Furniture.largeTable"; + path+= "." + s; + + Double x = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); + World w = Bukkit.getWorld(fc.getString(path+".Location.w")); + String face = fc.getString(path+".Location.face"); + Location l = new Location(w, x, y, z); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); + l.setYaw(yaw); + + HashMap teller = new HashMap(); + teller.put(0, getItemStack(fc, path+".settings.ItemStack_place1")); + teller.put(1, getItemStack(fc, path+".settings.ItemStack_place2")); + teller.put(2, getItemStack(fc, path+".settings.ItemStack_place3")); + teller.put(3, getItemStack(fc, path+".settings.ItemStack_place4")); + + new largeTable(l, main.getInstance(), getList(fc, path+".settings.ColorManager"), teller, s); + } + } + } + } + + public void loadSofa(){ + cc = new config(); + if(cc.ExistConfig(folder, "sofa.yml")){ + fc = cc.getConfig("sofa.yml", folder); + if(fc.isSet("Furniture.sofa")){ + for(String s : fc.getConfigurationSection("Furniture.sofa").getKeys(false)){ + String path = "Furniture.sofa"; + path+= "." + s; + + Double x = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); + World w = Bukkit.getWorld(fc.getString(path+".Location.w")); + String face = fc.getString(path+".Location.face"); + Location l = new Location(w, x, y, z); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); + l.setYaw(yaw); + + new sofa(l, 3, main.getInstance(), getList(fc, path+".settings.ColorManager"), s); + } + } + } + } + + public void loadtent1(){ + cc = new config(); + if(cc.ExistConfig(folder, "tent1.yml")){ + fc = cc.getConfig("tent1.yml", folder); + if(fc.isSet("Furniture.tent1")){ + for(String s : fc.getConfigurationSection("Furniture.tent1").getKeys(false)){ + String path = "Furniture.tent1"; + path+= "." + s; + Double x = fc.getDouble(path+".Location.x"); + Double y = fc.getDouble(path+".Location.y"); + Double z = fc.getDouble(path+".Location.z"); + World w = Bukkit.getWorld(fc.getString(path+".Location.w")); + String face = fc.getString(path+".Location.face"); + Location l = new Location(w, x, y, z); + float yaw = Utils.FaceToYaw(Utils.StringToFace(face)); + l.setYaw(yaw); + + new tent_1(l, main.getInstance(), s); + } + } + } + } + + public void saveStuhl(){ + cc = new config(); + fc = cc.getConfig("chair.yml",folder ); + if(!main.getInstance().stuehle.isEmpty()){ + String path = "Furniture.chair"; + for(chair s : main.getInstance().stuehle){ + path = "Furniture.chair."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",round(s.getLocation().getZ(), 2)); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + } + cc.saveConfig("chair.yml", fc, folder); + } + } + + public void saveLatern(){ + cc = new config(); + fc = cc.getConfig("lantern.yml",folder ); + if(!main.getInstance().laternen.isEmpty()){ + String path = "Furniture.lantern"; + for(latern s : main.getInstance().laternen){ + path = "Furniture.lantern."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",round(s.getLocation().getZ(), 2)); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + fc.set(path+".settings.Light", s.getBlockState()); + } + cc.saveConfig("lantern.yml", fc, folder); + } + } + + + public void saveSofa(){ + cc = new config(); + fc = cc.getConfig("sofa.yml",folder ); + if(!main.getInstance().sofas.isEmpty()){ + String path = "Furniture.sofa"; + for(sofa s : main.getInstance().sofas){ + path = "Furniture.sofa."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",round(s.getLocation().getZ(), 2)); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + if(!s.getItemListTisch().isEmpty()){ + int l = 0; + for(ItemStack is : s.getItemListTisch()){ + fc.set(path+".settings.ColorManager." + l + ".material", is.getType().name()); + fc.set(path+".settings.ColorManager." + l + ".durability", is.getDurability()); + l++; + } + } + } + cc.saveConfig("sofa.yml", fc, folder); + } + } + + public void saveItem(FileConfiguration fc, String s, ItemStack is){ + fc.set(s+".material", is.getType().name()); + fc.set(s+".durability", is.getDurability()); + fc.set(s+".amount", is.getAmount()); + + if(is.hasItemMeta()){ + if(is.getItemMeta().hasDisplayName()){fc.set(s+".displayName", is.getType().name());} + if(is.getItemMeta().hasLore()){fc.set(s+".lore", is.getItemMeta().getLore());} + + if(!is.getEnchantments().isEmpty()){ + for(Enchantment e : is.getEnchantments().keySet()){ + fc.set(s+".Enchantment." + e.getName() + ".lvl", e.getStartLevel()); + } + } + + if(is.getItemMeta() instanceof LeatherArmorMeta){ + LeatherArmorMeta lm = (LeatherArmorMeta) is.getItemMeta(); + fc.set(s+".LeatherMeta.Color.blue", lm.getColor().getBlue()); + fc.set(s+".LeatherMeta.Color.green", lm.getColor().getGreen()); + fc.set(s+".LeatherMeta.Color.red", lm.getColor().getRed()); + } + } + } + + public void saveTable(){ + cc = new config(); + fc = cc.getConfig("table.yml",folder ); + if(!main.getInstance().tische.isEmpty()){ + String path = "Furniture.table"; + for(table s : main.getInstance().tische){ + path = "Furniture.table."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",s.getLocation().getZ()); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + if(s.getItemStack()!=null){ + saveItem(fc, path, s.getItemStack()); + } + } + cc.saveConfig("table.yml", fc, folder); + } + } + + public void saveTent1(){ + cc = new config(); + fc = cc.getConfig("tent1.yml",folder ); + if(!main.getInstance().tents1.isEmpty()){ + String path = "Furniture.tent1"; + for(tent_1 s : main.getInstance().tents1){ + path = "Furniture.tent1."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",round(s.getLocation().getZ(), 2)); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + } + cc.saveConfig("tent1.yml", fc, folder); + } + } + + public void saveLargeTable(){ + cc = new config(); + fc = cc.getConfig("largeTable.yml",folder ); + if(!main.getInstance().tische2.isEmpty()){ + String path = "Furniture.largeTable"; + for(largeTable s : main.getInstance().tische2){ + path = "Furniture.largeTable."+s.getID(); + fc.set(path+".Location.x",round(s.getLocation().getX(), 2)); + fc.set(path+".Location.y",round(s.getLocation().getY(), 2)); + fc.set(path+".Location.z",round(s.getLocation().getZ(), 2)); + fc.set(path+".Location.w", s.getLocation().getWorld().getName()); + fc.set(path+".Location.face", s.getBlockFace().name()); + if(!s.getItemListTisch().isEmpty()){ + int l = 0; + for(ItemStack is : s.getItemListTisch()){ + fc.set(path+".settings.ColorManager." + l + ".material", is.getType().name()); + fc.set(path+".settings.ColorManager." + l + ".durability", is.getDurability()); + l++; + } + } + + if(!s.getTeller().isEmpty()){ + for(int l=0;l<=3;l++ ){ + try{ + ItemStack is = s.getTeller().get(l); + saveItem(fc, path, is); + }catch(Exception e){ + ItemStack is = new ItemStack(Material.AIR); + saveItem(fc, path, is); + } + } + } + } + cc.saveConfig("largeTable.yml", fc, folder); + } + } + + public void deleteFromConfig(String ID, String type){ + cc = new config(); + if(cc.ExistConfig(folder, type+".yml")){ + fc = cc.getConfig(type, folder); + if(fc.isSet("Furniture." + type + "." + ID)){ + fc.set("Furniture." + type + "." + ID, null); + } + cc.saveConfig(type, fc, folder); + } + } + + public static double round(double value, int places) { + if (places < 0) throw new IllegalArgumentException(); + + long factor = (long) Math.pow(10, places); + value = value * factor; + long tmp = Math.round(value); + return (double) tmp / factor; + } + + @SuppressWarnings("deprecation") + public void defaultCrafting(){ + cc = new config(); + fc = cc.getConfig("crafting.yml", ""); + fc.addDefaults(YamlConfiguration.loadConfiguration(main.getInstance().getResource("crafting.yml"))); + fc.options().copyDefaults(true); + cc.saveConfig("crafting.yml", fc, ""); + } + + public void loadCrafting(String s){ + ShapedRecipe recipe = new ShapedRecipe(returnResult(s)).shape(returnFragment(s)[0], returnFragment(s)[1], returnFragment(s)[2]); + for(Character c : returnMaterial(s).keySet()){ + if(!returnMaterial(s).get(c).equals(Material.AIR)){ + recipe.setIngredient(c.charValue(), returnMaterial(s).get(c)); + } + } + main.getInstance().getServer().addRecipe(recipe); + main.getInstance().crafting.put(s, returnResult(s)); + } + + @SuppressWarnings("deprecation") + public ItemStack returnResult(String s){ + cc = new config(); + fc = cc.getConfig("crafting.yml", ""); + String path = "Items." + s; + Integer MaterialID = fc.getInt(path+".material"); + Short shor = (short) fc.getInt(path+".durability"); + ItemStack is = new ItemStack(Material.getMaterial(MaterialID)); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(ChatColor.translateAlternateColorCodes('&', fc.getString(path+".name"))); + is.setItemMeta(im); + is.setDurability(shor); + is.setAmount(1); + return is; + } + + public String[] returnFragment(String s){ + cc = new config(); + fc = cc.getConfig("crafting.yml", ""); + String path = "Items." + s; + String recipe = fc.getString(path+".crafting.recipe"); + String[] fragments = recipe.split(","); + return fragments; + } + + public List returnCharacters(String s){ + List stringList = new ArrayList(); + for(String str: returnFragment(s)){ + String[] sl = str.split("(?!^)"); + for(String o : sl){ + if(!stringList.contains(o)){ + stringList.add(o); + } + } + } + return stringList; + } + + @SuppressWarnings("deprecation") + public HashMap returnMaterial(String s){ + cc = new config(); + fc = cc.getConfig("crafting.yml", ""); + String path = "Items." + s; + List stringList = returnCharacters(s); + HashMap materialHash = new HashMap(); + for(String str : stringList){ + Character chars = str.charAt(0); + Integer MaterialID = fc.getInt(path+".crafting.index." + str); + Material material = Material.getMaterial(MaterialID); + materialHash.put(chars, material); + } + return materialHash; + } } diff --git a/src/de/Ste3et_C0st/Furniture/Main/Utils.java b/src/de/Ste3et_C0st/Furniture/Main/Utils.java index 0248a5a..6121c43 100644 --- a/src/de/Ste3et_C0st/Furniture/Main/Utils.java +++ b/src/de/Ste3et_C0st/Furniture/Main/Utils.java @@ -1,6 +1,7 @@ package de.Ste3et_C0st.Furniture.Main; import java.util.List; +import java.util.Random; import org.bukkit.Location; import org.bukkit.World; @@ -29,7 +30,22 @@ public class Utils { } } - //NORDEN GEHT + public static BlockFace StringToFace(final String face) { + switch (face) { + case "NORTH": return BlockFace.NORTH; + case "EAST": return BlockFace.EAST; + case "SOUTH": return BlockFace.SOUTH; + case "WEST": return BlockFace.WEST; + default: return BlockFace.NORTH; + } + } + + public static int randInt(int min, int max) { + Random rand = new Random(); + int randomNum = rand.nextInt((max - min) + 1) + min; + return randomNum; + } + public static EulerAngle FaceEuler(final BlockFace face, Double x, Double y, Double z) { return new EulerAngle(x,y,z); } @@ -46,15 +62,14 @@ public class Utils { if(d<0){d+=.5;}else{d+=.5;} return d; } - - public static ArmorStand setArmorStand(Location location, EulerAngle angle, ItemStack is, Boolean Arm, List entityList, List locationList){ + + public static ArmorStand setArmorStand(Location location, EulerAngle angle, ItemStack is, Boolean Arm, String ID, List idList){ World w = location.getWorld(); - + String id = ID+"-"+idList.size(); for(Entity entity : w.getEntities()){ if(entity instanceof ArmorStand){ - if(location.equals(entity.getLocation())){ - entityList.add(entity); - if(locationList!=null){locationList.add(location);} + if(entity.getCustomName().equals(id)){ + idList.add(id); return (ArmorStand) entity; } } @@ -71,8 +86,19 @@ public class Utils { as.setVisible(false); as.setGravity(false); as.setBasePlate(false); - entityList.add(as); - if(locationList!=null){locationList.add(location);} + as.setCustomName(id); + idList.add(id); return as; } + + public static ArmorStand getArmorStandAtID(World w, String string){ + for(Entity e : w.getEntities()){ + if(e instanceof ArmorStand){ + if(e.getCustomName().equalsIgnoreCase(string)){ + return (ArmorStand) e; + } + } + } + return null; + } } diff --git a/src/de/Ste3et_C0st/Furniture/Main/command.java b/src/de/Ste3et_C0st/Furniture/Main/command.java index ec6bdd2..6a71151 100644 --- a/src/de/Ste3et_C0st/Furniture/Main/command.java +++ b/src/de/Ste3et_C0st/Furniture/Main/command.java @@ -1,25 +1,97 @@ package de.Ste3et_C0st.Furniture.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public class command implements CommandExecutor { @Override - public boolean onCommand(CommandSender arg0, Command arg1, String arg2,String[] arg3) { - if(arg0 instanceof Player == false){return true;} - Player p = (Player) arg0; - if(arg1.getName().equalsIgnoreCase("Furniture")){ - p.getInventory().addItem(main.getInstance().itemse.Sofa); - p.getInventory().addItem(main.getInstance().itemse.Laterne); - p.getInventory().addItem(main.getInstance().itemse.stuhl); - p.getInventory().addItem(main.getInstance().itemse.tisch); - p.getInventory().addItem(main.getInstance().itemse.tisch2); + public boolean onCommand(CommandSender sender, Command cmd, String arg2, String[] args) { + if(cmd.getName().equalsIgnoreCase("furniture")){ + String noPermissions = ChatColor.translateAlternateColorCodes('&', main.getInstance().getConfig().getString("config.Messages.NoPermissions")); + String notFound = ChatColor.translateAlternateColorCodes('&', main.getInstance().getConfig().getString("config.Messages.notFound")); + String PlayerNotFound = ChatColor.translateAlternateColorCodes('&', main.getInstance().getConfig().getString("config.Messages.PlayerNotFound")); + String help = "§7================[§2Furniture§7]================\n"; + help += "§2/furniture list | §8list all available furniture\n"; + help += "§2/furniture give | §8give one player one furniture\n"; + + if(sender instanceof Player){ + help += "§2/furniture give | §8give you an furniture\n"; + if(args.length == 2){ + if(args[0].equalsIgnoreCase("give")){ + if(!sender.hasPermission("furniture.give")){sender.sendMessage(noPermissions);return true;} + if(isExist(args[1])){ + if(!sender.hasPermission("furniture.give." + args[1].toLowerCase())){sender.sendMessage(noPermissions);return true;} + ((Player) sender).getInventory().addItem(getIS(args[1])); + return true; + }else{ + sender.sendMessage(notFound); + return true; + } + }else{ + sender.sendMessage(help); + return true; + } + } + } + help += "§7========================================="; + + if(args.length == 1){ + if(args[0].equalsIgnoreCase("list")){ + if(sender.hasPermission("furniture.list")){ + sender.sendMessage("§7Furniture: "); + for(String a : main.getInstance().crafting.keySet()){ + sender.sendMessage("§6- " + a); + } + return true; + }else{ + sender.sendMessage(noPermissions); + return true; + } + }else{ + sender.sendMessage(help); + } + }else if(args.length == 3){ + if(args[0].equalsIgnoreCase("give")){ + if(!sender.hasPermission("furniture.give")){sender.sendMessage(noPermissions);return true;} + if(!isExist(args[2])){sender.sendMessage(notFound);return true;} + if(!Bukkit.getPlayer(args[1]).isOnline()){sender.sendMessage(PlayerNotFound);return true;} + Player player = Bukkit.getPlayer(args[1]); + player.getInventory().addItem(getIS(args[2])); + return true; + }else{ + sender.sendMessage(help); + return true; + } + }else{ + sender.sendMessage(help); + return true; + } + } return false; } + public boolean isExist(String s){ + for(String a : main.getInstance().crafting.keySet()){ + if(a.equalsIgnoreCase(s)){ + return true; + } + } + return false; + } + public ItemStack getIS(String s ){ + for(String a : main.getInstance().crafting.keySet()){ + if(a.equalsIgnoreCase(s)){ + return main.getInstance().crafting.get(a); + } + } + return null; + } } diff --git a/src/de/Ste3et_C0st/Furniture/Main/config.java b/src/de/Ste3et_C0st/Furniture/Main/config.java index d001257..da99762 100644 --- a/src/de/Ste3et_C0st/Furniture/Main/config.java +++ b/src/de/Ste3et_C0st/Furniture/Main/config.java @@ -15,7 +15,7 @@ public class config public config() { - this.path = "plugins/DiceEaster"; + this.path = "plugins/Furniture/"; } public FileConfiguration createConfig(String name, String Folder) @@ -75,7 +75,6 @@ public class config } public boolean ExistConfig(String folder, String name){ - System.out.print(path + folder + "," + name); if(new File(path + folder, name).exists()){ return true; } diff --git a/src/de/Ste3et_C0st/Furniture/Main/main.java b/src/de/Ste3et_C0st/Furniture/Main/main.java index 205f459..ed13246 100644 --- a/src/de/Ste3et_C0st/Furniture/Main/main.java +++ b/src/de/Ste3et_C0st/Furniture/Main/main.java @@ -1,73 +1,89 @@ package de.Ste3et_C0st.Furniture.Main; +import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Random; + +import net.milkbowl.vault.Metrics; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockFace; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.EulerAngle; -import de.Ste3et_C0st.DiceEaster.DiceEaster; +import de.Ste3et_C0st.Furniture.Main.Manager; import de.Ste3et_C0st.Furniture.Listener.OnInteract; -import de.Ste3et_C0st.Furniture.Objects.largeTable; -import de.Ste3et_C0st.Furniture.Objects.laterne; -import de.Ste3et_C0st.Furniture.Objects.sofa; -import de.Ste3et_C0st.Furniture.Objects.stuhl; -import de.Ste3et_C0st.Furniture.Objects.tisch; +import de.Ste3et_C0st.Furniture.Objects.indoor.chair; +import de.Ste3et_C0st.Furniture.Objects.indoor.largeTable; +import de.Ste3et_C0st.Furniture.Objects.indoor.latern; +import de.Ste3et_C0st.Furniture.Objects.indoor.sofa; +import de.Ste3et_C0st.Furniture.Objects.indoor.table; +import de.Ste3et_C0st.Furniture.Objects.outdoor.tent_1; public class main extends JavaPlugin { private static main Main; public List sofas = new ArrayList(); - public List laternen = new ArrayList(); - public List stuehle = new ArrayList(); - public List tische = new ArrayList(); + public List laternen = new ArrayList(); + public List stuehle = new ArrayList(); + public List tische = new ArrayList
(); public List tische2 = new ArrayList(); - public ItemsEquipment itemse; - public DiceEaster dice; - + public HashMap crafting = new HashMap(); + public Manager mgr; + public List tents1 = new ArrayList(); + @SuppressWarnings("deprecation") @Override public void onEnable(){ - getCommand("Furniture").setExecutor(new command()); Main = this; - this.itemse = new ItemsEquipment(); getServer().getPluginManager().registerEvents(new OnInteract(), this); - dice = (DiceEaster) getServer().getPluginManager().getPlugin("DiceEaster"); + getCommand("furniture").setExecutor(new command()); + getConfig().addDefaults(YamlConfiguration.loadConfiguration(getResource("config.yml"))); + getConfig().options().copyDefaults(true); + saveConfig(); + + if(getServer().getPluginManager().isPluginEnabled("Vault") && getConfig().getBoolean("config.UseMetrics")){ + try + { + Metrics metrics = new Metrics(this); + metrics.start(); + } + catch (IOException localIOException) {} + } + + this.mgr = new Manager(); + mgr.loadLargeTisch(); + mgr.loadLatern(); + mgr.loadSofa(); + mgr.loadStuhl(); + mgr.loadTisch(); + mgr.loadtent1(); + mgr.defaultCrafting(); addCrafting(); } @Override public void onDisable(){ - + mgr.saveLargeTable(); + mgr.saveLatern(); + mgr.saveSofa(); + mgr.saveStuhl(); + mgr.saveTable(); + mgr.saveTent1(); + getServer().resetRecipes(); } public void addCrafting(){ - ShapedRecipe grinderRecipe = new ShapedRecipe(itemse.Sofa).shape("#0#", "###", "+0+").setIngredient('+', Material.FENCE). - setIngredient('#', Material.WOOL); - getServer().addRecipe(grinderRecipe); - - grinderRecipe = new ShapedRecipe(itemse.Laterne).shape("0#0", "-+-", "0E0").setIngredient('+', Material.TORCH). - setIngredient('#', Material.WOOD_PLATE).setIngredient('-', Material.STICK).setIngredient('E', Material.OBSIDIAN); - getServer().addRecipe(grinderRecipe); - - grinderRecipe = new ShapedRecipe(itemse.Laterne).shape("0#0", "-+-", "0E0").setIngredient('+', Material.TORCH). - setIngredient('#', Material.WOOD_PLATE).setIngredient('-', Material.STICK).setIngredient('E', Material.OBSIDIAN); - getServer().addRecipe(grinderRecipe); - - grinderRecipe = new ShapedRecipe(itemse.stuhl).shape("0#0", "0#0", "E0E").setIngredient('#', Material.TRAP_DOOR). - setIngredient('E', Material.STICK); - getServer().addRecipe(grinderRecipe); - - grinderRecipe = new ShapedRecipe(itemse.tisch).shape("0#0", "0E0", "0+0").setIngredient('#', Material.TRAP_DOOR). - setIngredient('E', Material.STICK).setIngredient('+', Material.WOOD_STEP); - getServer().addRecipe(grinderRecipe); - - grinderRecipe = new ShapedRecipe(itemse.tisch2).shape("###", "###", "E0E").setIngredient('#', Material.STAINED_GLASS_PANE). - setIngredient('E', Material.BONE); - getServer().addRecipe(grinderRecipe); + mgr.loadCrafting("largeTable"); + mgr.loadCrafting("table"); + mgr.loadCrafting("lantern"); + mgr.loadCrafting("sofa"); + mgr.loadCrafting("chair"); + mgr.loadCrafting("tent1"); } public static String getCardinalDirection(Player player) { @@ -153,6 +169,99 @@ public class main extends JavaPlugin { } return true; } + + public boolean canPlaceLarge(Player p, Location location, BlockFace b, Integer length, Integer width){ + if(b==null&&length==null&&width==null){ + if(!location.getBlock().getType().equals(Material.AIR)){ + return false; + } + } + location = main.getNew(location, b.getOppositeFace(), 2D, 0D); + if(b!=null&&length!=null&&width!=null){ + for(int i = 0; i<= length-1; i++){ + for(int l = 0; l<= width-1; l++){ + if(!getNew(location, b,(double) l,(double) i).getBlock().getType().equals(Material.AIR)){ + return false; + } + } + } + } + return true; + } + + public List getFunList(){ + List loc = new ArrayList(); + if(!this.stuehle.isEmpty()){ + for(chair s : stuehle){ + loc.add(s.getLocation()); + } + } + if(!this.laternen.isEmpty()){ + for(latern l : laternen){ + loc.add(l.getLocation()); + } + } + if(!this.tische2.isEmpty()){ + for(largeTable l : tische2){ + loc.add(l.getLocation()); + } + } + if(!this.sofas.isEmpty()){ + for(sofa s : sofas){ + loc.add(s.getLocation()); + } + } + if(!this.tische.isEmpty()){ + for(table t : tische){ + loc.add(t.getLocation()); + } + } + return loc; + } + public static String createRandomRegistryId() + { + String val = ""; + int ranChar = 65 + (new Random()).nextInt(90-65); + char ch = (char)ranChar; + val += ch; + Random r = new Random(); + int numbers = 100000 + (int)(r.nextFloat() * 899900); + val += String.valueOf(numbers); + val += "-"; + for(int i = 0; i<6;){ + int ranAny = 48 + (new Random()).nextInt(90-65); + if(!(57 < ranAny && ranAny<= 65)){ + char c = (char)ranAny; + val += c; + i++; + } + } + + return val; + } + public static main getInstance() {return Main;} + + public boolean canPlaceTent(Player p, Location location, BlockFace b, Integer length, Integer width, Integer height){ + if(b==null&&length==null&&width==null){ + if(!location.getBlock().getType().equals(Material.AIR)){ + return false; + } + } + location = main.getNew(location, b.getOppositeFace(), 3D, 0D); + if(b!=null&&length!=null&&width!=null){ + for(int i = 0; i<= length-1; i++){ + for(int l = 0; l<= width-1; l++){ + for(int y=0;y<=height-1;y++){ + if(!getNew(location, b,(double) l,(double) i).add(0,y,0).getBlock().getType().equals(Material.AIR)){ + return false; + } + } + + } + } + } + return true; + } } diff --git a/src/de/Ste3et_C0st/Furniture/Objects/stuhl.java b/src/de/Ste3et_C0st/Furniture/Objects/indoor/chair.java similarity index 67% rename from src/de/Ste3et_C0st/Furniture/Objects/stuhl.java rename to src/de/Ste3et_C0st/Furniture/Objects/indoor/chair.java index 5387d81..05fd047 100644 --- a/src/de/Ste3et_C0st/Furniture/Objects/stuhl.java +++ b/src/de/Ste3et_C0st/Furniture/Objects/indoor/chair.java @@ -1,4 +1,4 @@ -package de.Ste3et_C0st.Furniture.Objects; +package de.Ste3et_C0st.Furniture.Objects.indoor; import java.util.ArrayList; import java.util.List; @@ -6,11 +6,12 @@ import java.util.List; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -22,17 +23,22 @@ import org.bukkit.util.EulerAngle; import de.Ste3et_C0st.Furniture.Main.Utils; import de.Ste3et_C0st.Furniture.Main.main; -public class stuhl implements Listener { +public class chair implements Listener { - List armorList = new ArrayList(); + List IDList = new ArrayList(); Location loc = null; BlockFace b = null; - + World w = null; + private String id; + public String getID(){return this.id;} public Location getLocation(){return this.loc;} public BlockFace getBlockFace(){return this.b;} - public stuhl(Location loc, Plugin plugin){ + public chair(Location loc, Plugin plugin, String id){ this.loc = loc.getBlock().getLocation(); + this.id = id; + this.b = Utils.yawToFace(loc.getYaw()); + this.w = this.loc.getWorld(); BlockFace b = Utils.yawToFace(loc.getYaw()).getOppositeFace(); Location center = Utils.getCenter(loc); Location sitz = new Location(center.getWorld(), center.getX(), center.getY(), center.getZ()); @@ -50,12 +56,12 @@ public class stuhl implements Listener { sitz.setYaw(Utils.FaceToYaw(b)); lehne.setYaw(Utils.FaceToYaw(b)); - Utils.setArmorStand(sitz, null, new ItemStack(Material.TRAP_DOOR), false, armorList, null); - Utils.setArmorStand(lehne, new EulerAngle(1.57, .0, .0), new ItemStack(Material.TRAP_DOOR), false, armorList, null); - Utils.setArmorStand(feet1, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet2, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet3, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet4, null, new ItemStack(Material.LEVER), false, armorList, null); + Utils.setArmorStand(sitz, null, new ItemStack(Material.TRAP_DOOR), false,getID(),IDList); + Utils.setArmorStand(lehne, new EulerAngle(1.57, .0, .0), new ItemStack(Material.TRAP_DOOR), false,getID(),IDList); + Utils.setArmorStand(feet1, null, new ItemStack(Material.LEVER), false,getID(),IDList); + Utils.setArmorStand(feet2, null, new ItemStack(Material.LEVER), false,getID(),IDList); + Utils.setArmorStand(feet3, null, new ItemStack(Material.LEVER), false,getID(),IDList); + Utils.setArmorStand(feet4, null, new ItemStack(Material.LEVER), false,getID(),IDList); main.getInstance().stuehle.add(this); plugin.getServer().getPluginManager().registerEvents(this, plugin); } @@ -80,41 +86,39 @@ public class stuhl implements Listener { } */ - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent e){ + @EventHandler(priority = EventPriority.NORMAL) + private void onInteract(PlayerInteractAtEntityEvent e){ + if(e.isCancelled()){return;} Player player = e.getPlayer(); if(e.getRightClicked() instanceof ArmorStand){ - if(armorList.contains(e.getRightClicked())){ + if(IDList.contains(e.getRightClicked().getCustomName())){ e.setCancelled(true); - ItemStack is = player.getItemInHand(); - if(is!=null){ - if(armorList.contains(e.getRightClicked())){ - armorList.get(0).setPassenger(player); - } - } + Utils.getArmorStandAtID(w, IDList.get(0)).setPassenger(player); } } } public void delete(Boolean b){ if(b){ - armorList.get(0).getLocation().getWorld().dropItem(armorList.get(0).getLocation().getBlock().getLocation().add(0, 1, 0), main.getInstance().itemse.stuhl); - for(Entity entity : armorList){ - ArmorStand as = (ArmorStand) entity; - entity.getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); - entity.remove(); + getLocation().getWorld().dropItem(getLocation(), main.getInstance().crafting.get("chair")); + for(String ids : IDList){ + ArmorStand as = Utils.getArmorStandAtID(w, ids); + getLocation().getWorld().playEffect(as.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); + as.remove(); + main.getInstance().mgr.deleteFromConfig(getID(), "chair"); } } this.loc = null; - armorList.clear(); + IDList.clear(); main.getInstance().stuehle.remove(this); } - @EventHandler + @EventHandler(priority = EventPriority.NORMAL) public void damage(EntityDamageByEntityEvent e){ + if(e.isCancelled()){return;} if(e.getDamager() instanceof Player){ if(e.getEntity() instanceof ArmorStand){ - if(armorList.contains(e.getEntity())){ + if(IDList.contains(e.getEntity().getCustomName())){ delete(true); } } diff --git a/src/de/Ste3et_C0st/Furniture/Objects/indoor/largeTable.java b/src/de/Ste3et_C0st/Furniture/Objects/indoor/largeTable.java new file mode 100644 index 0000000..a7797f2 --- /dev/null +++ b/src/de/Ste3et_C0st/Furniture/Objects/indoor/largeTable.java @@ -0,0 +1,277 @@ +package de.Ste3et_C0st.Furniture.Objects.indoor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.bukkit.Effect; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.util.EulerAngle; + +import de.Ste3et_C0st.Furniture.Main.Utils; +import de.Ste3et_C0st.Furniture.Main.main; + +public class largeTable implements Listener { + + private List idList = new ArrayList(); + private List tellerIDS = new ArrayList(); + private Location loc = null; + private BlockFace b = null; + private String id; + private World w; + public String getID(){return this.id;} + public Location getLocation(){return this.loc;} + public BlockFace getBlockFace(){return this.b;} + + public largeTable(Location loc, Plugin plugin, List iL, HashMap tellerItems, String id){ + List armorlist = new ArrayList(); + this.loc = loc; + this.b = Utils.yawToFace(loc.getYaw()); + this.id = id; + this.w = loc.getWorld(); + ItemStack IS1 =null; + ItemStack IS2 =null; + ItemStack IS3 =null; + ItemStack IS4 =null; + + if(tellerItems != null){ + if(tellerItems.containsKey(0)){IS1=tellerItems.get(0);} + if(tellerItems.containsKey(1)){IS2=tellerItems.get(1);} + if(tellerItems.containsKey(2)){IS3=tellerItems.get(2);} + if(tellerItems.containsKey(3)){IS4=tellerItems.get(3);} + } + + Location location = Utils.getCenter(loc.getBlock().getLocation()); + float yaw = Utils.FaceToYaw(this.b); + location = main.getNew(location, this.b, 0.1, 0.28); + location.add(0,.2,0); + Double winkel = 1.57; + int iTems = 0; + for(int x=1; x<=3;x++){ + Location l = null; + l = main.getNew(location, this.b, 0.0, x*-.63); + l.add(0,-1.2,0); + l.setYaw(yaw); + ItemStack iTemStack_1 = new ItemStack(Material.STAINED_GLASS_PANE); + ItemStack iTemStack_2 = new ItemStack(Material.STAINED_GLASS_PANE); + ItemStack iTemStack_3 = new ItemStack(Material.STAINED_GLASS_PANE); + if(iL!=null&&!iL.isEmpty()){ + if(iL.get(iTems)!=null){ + iTemStack_1=iL.get(iTems); + iTems++; + } + if(iL.get(iTems)!=null){ + iTemStack_2=iL.get(iTems); + iTems++; + } + if(iL.get(iTems)!=null){ + iTemStack_3=iL.get(iTems); + iTems++; + } + } + + ArmorStand as = Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_1, false,getID(),idList); + armorlist.add(as); + l = main.getNew(location, this.b, 0.63, x*-.63); + l.add(0,-1.2,0); + l.setYaw(yaw); + as = Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_2, false,getID(),idList); + armorlist.add(as); + l = main.getNew(location, this.b, 1.26, x*-.63); + l.add(0,-1.2,0); + l.setYaw(yaw); + as = Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_3, false,getID(),idList); + armorlist.add(as); + } + + Location middle = Utils.getCenter(armorlist.get(0).getLocation()); + Location mitteTisch = Utils.getCenter(armorlist.get(4).getLocation().getBlock().getLocation()); + middle.add(0, -.9, 0); + Location feet1 = main.getNew(middle, this.b, -.2, .1); + Location feet2 = main.getNew(middle, this.b, -.2, -1.3); + Location feet3 = main.getNew(middle, this.b, 1.1, .1); + Location feet4 = main.getNew(middle, this.b, 1.1, -1.3); + + + double hight = .67; + + Location t1 = main.getNew(mitteTisch, this.b, -.95, .4).add(0,hight,0); + Location t2 = main.getNew(mitteTisch, this.b, -.4, -.92).add(0,hight,0); + Location t3 = main.getNew(mitteTisch, this.b, .92, -.36).add(0,hight,0); + Location t4 = main.getNew(mitteTisch, this.b, .4, .92).add(0,hight,0); + + float yaw1 = yaw; + float yaw2 = yaw1-90; + float yaw3 = yaw2-90; + float yaw4 = yaw3-90; + + t1.setYaw(yaw1); + t2.setYaw(yaw2); + t3.setYaw(yaw3); + t4.setYaw(yaw4); + + feet1.setYaw(yaw); + feet2.setYaw(yaw); + feet3.setYaw(yaw); + feet4.setYaw(yaw); + + Utils.setArmorStand(feet1, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, getID(), idList); + Utils.setArmorStand(feet2, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, getID(), idList); + Utils.setArmorStand(feet3, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, getID(), idList); + Utils.setArmorStand(feet4, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, getID(), idList); + ArmorStand as1 = Utils.setArmorStand(t1, new EulerAngle(0, 0, 0), IS1, true, getID(), idList); + ArmorStand as2 = Utils.setArmorStand(t2, new EulerAngle(0, 0, 0), IS2, true, getID(), idList); + ArmorStand as3 = Utils.setArmorStand(t3, new EulerAngle(0, 0, 0), IS3, true, getID(), idList); + ArmorStand as4 = Utils.setArmorStand(t4, new EulerAngle(0, 0, 0), IS4, true, getID(), idList); + + tellerIDS.add(as1.getCustomName()); + tellerIDS.add(as2.getCustomName()); + tellerIDS.add(as3.getCustomName()); + tellerIDS.add(as4.getCustomName()); + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + main.getInstance().tische2.add(this); + } + + public void delete(boolean b){ + if(b){ + getLocation().getWorld().dropItem(getLocation(), main.getInstance().crafting.get("largeTable")); + + for(String s : tellerIDS){ + ArmorStand as = Utils.getArmorStandAtID(w, s); + if(as!=null){ + if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){ + getLocation().getWorld().dropItem(getLocation(), as.getItemInHand()); + } + } + } + + for(String s : this.idList){ + ArmorStand as = Utils.getArmorStandAtID(w, s); + if(as!=null && as.getHelmet()!= null && as.getHelmet().getType()!=null){ + loc.getWorld().playEffect(loc, Effect.STEP_SOUND, as.getHelmet().getType()); + } + as.remove(); + } + main.getInstance().mgr.deleteFromConfig(getID(), "largeTable"); + } + + this.tellerIDS.clear(); + this.idList.clear(); + main.getInstance().tische2.remove(this); + } + + @EventHandler(priority = EventPriority.NORMAL) + private void onInteract(PlayerInteractAtEntityEvent e){ + if(e.isCancelled()){return;} + Player player = e.getPlayer(); + if(e.getRightClicked() instanceof ArmorStand){ + if(this.idList.contains(e.getRightClicked().getCustomName())){ + e.setCancelled(true); + ItemStack is = player.getItemInHand(); + if(is!=null){ + if(is.getType().equals(Material.INK_SACK)){ + Short druability = is.getDurability(); + Integer amount = is.getAmount(); + if(amount>this.idList.size()-4 || player.getGameMode().equals(GameMode.CREATIVE)){amount=this.idList.size()-4;} + List list = new ArrayList(); + + for(String s : this.idList){ + ArmorStand as = Utils.getArmorStandAtID(w, s); + if(as!=null){ + ItemStack item = as.getHelmet(); + if(item.getDurability() != main.getFromDey(druability)){ + list.add(as); + } + } + } + + try{ + for(int i = 0; i<=amount-1;i++){ + Entity entity = list.get(i); + if(entity instanceof ArmorStand){ + ArmorStand as = (ArmorStand) entity; + ItemStack item = as.getHelmet(); + item.setDurability(main.getFromDey(druability)); + as.setHelmet(item); + } + } + }catch(Exception ex){} + + + if(!player.getGameMode().equals(GameMode.CREATIVE)){ + is.setAmount(is.getAmount()-amount); + player.getInventory().setItem(player.getInventory().getHeldItemSlot(), is); + player.updateInventory(); + } + }else if(!is.getType().isBlock() || is.getType().equals(Material.AIR)){ + BlockFace b = Utils.yawToFace(player.getLocation().getYaw()); + ArmorStand as = null; + + for(String s : this.tellerIDS){ + ArmorStand armorStand = Utils.getArmorStandAtID(w, s); + BlockFace b2 = Utils.yawToFace(armorStand.getLocation().getYaw()); + if(b2.equals(b)){ + as = armorStand; + break; + } + } + + if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} + as.setItemInHand(is); + + player.getInventory().clear(player.getInventory().getHeldItemSlot()); + player.updateInventory(); + } + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void damage(EntityDamageByEntityEvent e){ + if(e.isCancelled()){return;} + if(e.getDamager() instanceof Player){ + if(e.getEntity() instanceof ArmorStand){ + if(this.idList.contains(e.getEntity().getCustomName())){ + delete(true); + } + } + } + } + + public List getItemListTisch(){ + List items = new ArrayList(); + for(int i = 0; i<=8;i++){ + items.add(Utils.getArmorStandAtID(w, idList.get(i)).getHelmet()); + } + return items; + } + + public HashMap getTeller(){ + HashMap teller = new HashMap(); + for(String s : tellerIDS){ + try{ + ArmorStand as = Utils.getArmorStandAtID(w, s); + teller.put(teller.size(), as.getItemInHand()); + }catch(Exception e){ + teller.put(teller.size(), new ItemStack(Material.AIR)); + } + } + return teller; + } +} diff --git a/src/de/Ste3et_C0st/Furniture/Objects/laterne.java b/src/de/Ste3et_C0st/Furniture/Objects/indoor/latern.java similarity index 65% rename from src/de/Ste3et_C0st/Furniture/Objects/laterne.java rename to src/de/Ste3et_C0st/Furniture/Objects/indoor/latern.java index 5612149..fd29457 100644 --- a/src/de/Ste3et_C0st/Furniture/Objects/laterne.java +++ b/src/de/Ste3et_C0st/Furniture/Objects/indoor/latern.java @@ -1,4 +1,4 @@ -package de.Ste3et_C0st.Furniture.Objects; +package de.Ste3et_C0st.Furniture.Objects.indoor; import java.util.ArrayList; import java.util.List; @@ -7,13 +7,15 @@ import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -23,21 +25,25 @@ import org.bukkit.plugin.Plugin; import de.Ste3et_C0st.Furniture.Main.Utils; import de.Ste3et_C0st.Furniture.Main.main; -public class laterne implements Listener { - List armorList = new ArrayList(); - Block b; - Location loc = null; - Boolean bool = true; - - BlockFace bFace = null; - +public class latern implements Listener { + private List idList = new ArrayList(); + private Block b; + private Location loc = null; + private Boolean bool = true; + private BlockFace bFace = null; + private String id; + private World w; + public String getID(){return this.id;} public Location getLocation(){return this.loc;} public BlockFace getBlockFace(){return this.bFace;} public Boolean getBlockState(){return this.bool;} - public laterne(Location loc, Plugin plugin, Boolean bool){ + public latern(Location loc, Plugin plugin, Boolean bool, String id){ this.loc = loc; this.bool = bool; + this.id = id; + this.bFace = Utils.yawToFace(loc.getYaw()); + this.w = loc.getWorld(); Location center = Utils.getCenter(loc); b = center.getWorld().getBlockAt(center); if(bool){ @@ -54,13 +60,13 @@ public class laterne implements Listener { Location right_upper = new Location(obsidian.getWorld(), obsidian.getX()-0.21, obsidian.getY()+.62, obsidian.getZ()-0.21); Location right_down = new Location(obsidian.getWorld(), obsidian.getX()+0.21, obsidian.getY() + .62, obsidian.getZ() -0.21); - Utils.setArmorStand(obsidian, null, new ItemStack(Material.OBSIDIAN), false, armorList, null); - Utils.setArmorStand(location.add(0,0,0), null, new ItemStack(Material.WOOD_PLATE), false, armorList, null); + Utils.setArmorStand(obsidian, null, new ItemStack(Material.OBSIDIAN), false,getID(),idList); + Utils.setArmorStand(location.add(0,0,0), null, new ItemStack(Material.WOOD_PLATE), false,getID(), idList); - Utils.setArmorStand(left_down, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(left_upper, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(right_upper, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(right_down, null, new ItemStack(Material.LEVER), false, armorList, null); + Utils.setArmorStand(left_down, null, new ItemStack(Material.LEVER), false,getID(), idList); + Utils.setArmorStand(left_upper, null, new ItemStack(Material.LEVER), false,getID(), idList); + Utils.setArmorStand(right_upper, null, new ItemStack(Material.LEVER), false,getID(), idList); + Utils.setArmorStand(right_down, null, new ItemStack(Material.LEVER), false,getID(), idList); Bukkit.getServer().getPluginManager().registerEvents(this, plugin); main.getInstance().laternen.add(this); } @@ -80,59 +86,58 @@ public class laterne implements Listener { } } - /* - @EventHandler - public void onHit(PlayerMoveEvent e){ - Player p = e.getPlayer(); - if(!p.isInsideVehicle() && loc!=null){ - if(e.getTo().getBlock().getLocation().equals(loc.getBlock().getLocation()) || - e.getTo().getBlock().getLocation().equals(loc.getBlock().getLocation().add(0,1,0))){ - p.teleport(e.getFrom()); - } - } - } - */ - public void delete(Boolean b){ if(b){ - armorList.get(0).getLocation().getWorld().dropItem(this.b.getLocation(), main.getInstance().itemse.Laterne); - for(Entity entity : armorList){ - ArmorStand as = (ArmorStand) entity; - entity.getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); - entity.remove(); + getLocation().getWorld().dropItem(getLocation(), main.getInstance().crafting.get("lantern")); + for(String s : idList){ + ArmorStand as = Utils.getArmorStandAtID(w,s); + as.getWorld().playEffect(as.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); + as.remove(); + main.getInstance().mgr.deleteFromConfig(getID(), "lantern"); } } if(this.b!=null&&!this.b.getType().equals(Material.AIR)){this.b.setType(Material.AIR);} this.bool = null; this.loc = null; - armorList.clear(); + this.idList.clear(); main.getInstance().laternen.remove(this); } @EventHandler - public void onInteract(PlayerInteractAtEntityEvent e){ + public void onBlockBreak(BlockBreakEvent e){ + if(e.getBlock()!=null&&e.getBlock().equals(b)){ + delete(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + private void onInteract(PlayerInteractAtEntityEvent e){ + if(e.isCancelled()){return;} Player player = e.getPlayer(); if(e.getRightClicked() instanceof ArmorStand){ - if(armorList.contains(e.getRightClicked())){ + if(this.idList.contains(e.getRightClicked().getName())){ e.setCancelled(true); ItemStack is = player.getItemInHand(); if(is!=null){ if(is.getType().equals(Material.FLINT_AND_STEEL)){ b.setType(Material.TORCH); + bool = true; }else if(is.getType().equals(Material.WATER_BUCKET)){ b.setType(Material.REDSTONE_TORCH_OFF); + bool = false; } } } } } - @EventHandler + @EventHandler(priority = EventPriority.NORMAL) public void damage(EntityDamageByEntityEvent e){ + if(e.isCancelled()){return;} if(e.getDamager() instanceof Player){ if(e.getEntity() instanceof ArmorStand){ - if(armorList.contains(e.getEntity())){ + if(this.idList.contains(e.getEntity().getName())){ delete(true); } } diff --git a/src/de/Ste3et_C0st/Furniture/Objects/sofa.java b/src/de/Ste3et_C0st/Furniture/Objects/indoor/sofa.java similarity index 51% rename from src/de/Ste3et_C0st/Furniture/Objects/sofa.java rename to src/de/Ste3et_C0st/Furniture/Objects/indoor/sofa.java index 5ed7e6c..2617782 100644 --- a/src/de/Ste3et_C0st/Furniture/Objects/sofa.java +++ b/src/de/Ste3et_C0st/Furniture/Objects/indoor/sofa.java @@ -1,4 +1,4 @@ -package de.Ste3et_C0st.Furniture.Objects; +package de.Ste3et_C0st.Furniture.Objects.indoor; import java.util.ArrayList; import java.util.List; @@ -7,13 +7,14 @@ import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.inventory.ItemStack; @@ -24,16 +25,25 @@ import de.Ste3et_C0st.Furniture.Main.Utils; import de.Ste3et_C0st.Furniture.Main.main; public class sofa implements Listener { - private List armorList = new ArrayList(); - private List sitz = new ArrayList(); - private List location = new ArrayList(); - + private List idList = new ArrayList(); private ItemStack is; private Double place; + private BlockFace b; private short color = 0; + private Location loc = null; + private String id; + private World w; + public String getID(){return this.id;} + public Location getLocation(){return this.loc;} + public BlockFace getBlockFace(){return this.b;} - public sofa(Location loc, Integer lengt, Plugin plugin){ + public sofa(Location loc, Integer lengt, Plugin plugin, List list, String id){ + List sitz = new ArrayList(); + this.w = loc.getWorld(); + this.loc = loc; this.place = 0.2; + this.id = id; + this.b = Utils.yawToFace(loc.getYaw()); is = new ItemStack(Material.CARPET); is.setDurability(color); BlockFace b = Utils.yawToFace(loc.getYaw()).getOppositeFace(); @@ -56,31 +66,43 @@ public class sofa implements Listener { Location feet3 = main.getNew(looking, b, place + .5, .2D); Location feet4 = main.getNew(looking, b, place + .5, lengt.doubleValue()-.2D); - Utils.setArmorStand(feet1, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet2, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet3, null, new ItemStack(Material.LEVER), false, armorList, null); - Utils.setArmorStand(feet4, null, new ItemStack(Material.LEVER), false, armorList, null); + Utils.setArmorStand(feet1, null, new ItemStack(Material.LEVER), false,getID(),idList); + Utils.setArmorStand(feet2, null, new ItemStack(Material.LEVER), false,getID(),idList); + Utils.setArmorStand(feet3, null, new ItemStack(Material.LEVER), false,getID(),idList); + Utils.setArmorStand(feet4, null, new ItemStack(Material.LEVER), false,getID(),idList); Location carpetHight = new Location(looking.getWorld(), loc.getBlockX(), loc.getBlockY() -1 , loc.getBlockZ()); carpetHight.setYaw(Utils.FaceToYaw(b)); - //sitz carpetHight = main.getNew(carpetHight, b, .25,.3); Double d = .02; float facing = Utils.FaceToYaw(b); + int l = 0; for(Double i = .0; i<=lengt; i+=0.65){ - //SITZ - location.add(main.getNew(carpetHight, b, place,(double) d).getBlock().getLocation().add(0, 1, 0)); Location carpet = main.getNew(carpetHight, b, place,(double) d); carpet.setYaw(facing); - ArmorStand as = Utils.setArmorStand(carpet, null, is, false, armorList, null); + ArmorStand as = null; + if(list!=null&&!list.isEmpty() && list.get(l)!=null){ + as = Utils.setArmorStand(carpet, null, list.get(l), false,getID(),idList); + }else{ + as = Utils.setArmorStand(carpet, null, is, false,getID(),idList); + } sitz.add(as); + l++; + //OBERER TEIL Location location = main.getNew(carpetHight, b, place-.25,(double) d); location.setYaw(facing); - Utils.setArmorStand(location, new EulerAngle(1.57, .0, .0), is, false, armorList, null); + + if(list!=null&&!list.isEmpty() && list.get(l)!=null){ + Utils.setArmorStand(location, new EulerAngle(1.57, .0, .0), list.get(l), false,getID(),idList); + }else{ + Utils.setArmorStand(location, new EulerAngle(1.57, .0, .0), is, false,getID(),idList); + } + l++; if(d<=0D){d = 0.00;} d+=.58; } + Float yaw1= facing; Float yaw2= facing; Location last = main.getNew(sitz.get(sitz.size()-1).getLocation(), b, 0D, 0.26D); @@ -88,97 +110,106 @@ public class sofa implements Listener { Location first = main.getNew(new Location(loc.getWorld(), loc.getX(), last.getY(), loc.getZ()), b, place+.25, 0.07D); first.setYaw(yaw2-90); - Utils.setArmorStand(first.add(0,-.05,0), new EulerAngle(1.57, .0, .0), is, false, armorList, null); - Utils.setArmorStand(last.add(0,-.05,0), new EulerAngle(1.57, .0, .0), is, false, armorList, null); + Utils.setArmorStand(first.add(0,-.05,0), new EulerAngle(1.57, .0, .0), is, false,getID(),idList); + Utils.setArmorStand(last.add(0,-.05,0), new EulerAngle(1.57, .0, .0), is, false,getID(),idList); plugin.getServer().getPluginManager().registerEvents(this, plugin); main.getInstance().sofas.add(this); } - @EventHandler - public void onWaterFlow(BlockFromToEvent e){ + /*@EventHandler + private void onWaterFlow(BlockFromToEvent e){ Location locTo = e.getToBlock().getLocation(); if(location!=null && !location.isEmpty()){ if(location.contains(locTo) || location.contains(locTo.add(0,1,0))){ e.setCancelled(true); } } - } - - /* - @EventHandler - public void onHit(PlayerMoveEvent e){ - Player p = e.getPlayer(); - if(!p.isInsideVehicle() && location!=null){ - if(location.contains(e.getTo().getBlock().getLocation()) || location.contains(e.getTo().getBlock().getLocation().add(0,-1,0))){ - p.teleport(e.getFrom()); - } - } }*/ public void delete(Boolean b){ if(b){ - armorList.get(0).getLocation().getWorld().dropItem(armorList.get(0).getLocation().getBlock().getLocation().add(0, 1, 0), main.getInstance().itemse.Sofa); - for(Entity entity : armorList){ - ArmorStand as = (ArmorStand) entity; - entity.getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); - entity.remove(); + getLocation().getWorld().dropItem(getLocation(), main.getInstance().crafting.get("sofa")); + for(String s : idList){ + ArmorStand as = Utils.getArmorStandAtID(this.w, s); + as.getWorld().playEffect(as.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); + as.remove(); + main.getInstance().mgr.deleteFromConfig(getID(), "sofa"); } } - location.clear(); - armorList.clear(); + idList.clear(); main.getInstance().sofas.remove(this); } - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent e){ + @EventHandler(priority = EventPriority.NORMAL) + private void onInteract(PlayerInteractAtEntityEvent e){ + if(e.isCancelled()){return;} Player player = e.getPlayer(); if(e.getRightClicked() instanceof ArmorStand){ - if(armorList.contains(e.getRightClicked())){ + if(idList.contains(e.getRightClicked().getCustomName())){ e.setCancelled(true); ItemStack is = player.getItemInHand(); + ArmorStand armorStand = Utils.getArmorStandAtID(w, e.getRightClicked().getCustomName()); if(is!=null){ if(is.getType().equals(Material.INK_SACK)){ + e.getRightClicked().sendMessage("test#2"); Short druability = is.getDurability(); - Integer amount = is.getAmount(); - if(amount>armorList.size() || player.getGameMode().equals(GameMode.CREATIVE)){amount=armorList.size();} + Integer amount = is.getAmount() + 4; + if(amount>idList.size() || player.getGameMode().equals(GameMode.CREATIVE)){amount=idList.size();} List list = new ArrayList(); - for(Entity entity : armorList){ - if(entity instanceof ArmorStand){ - ArmorStand as = (ArmorStand) entity; - ItemStack item = as.getHelmet(); - if(item.getDurability() != main.getFromDey(druability)){ - list.add(entity); + for(String s : idList){ + ArmorStand as = Utils.getArmorStandAtID(w, s); + if(as.getHelmet().getType().equals(Material.CARPET)){ + ItemStack item = as.getHelmet(); + if(item.getDurability() != main.getFromDey(druability)){ + list.add(as); + } } - } } - for(int i = 0; i<=amount-1;i++){ - Entity entity = list.get(i); - if(entity instanceof ArmorStand){ - ArmorStand as = (ArmorStand) entity; - ItemStack item = as.getHelmet(); - item.setDurability(main.getFromDey(druability)); - as.setHelmet(item); + try{ + for(int i = 0; i<=amount-1;i++){ + Entity entity = list.get(i); + if(entity instanceof ArmorStand){ + ArmorStand as = (ArmorStand) entity; + ItemStack item = as.getHelmet(); + item.setDurability(main.getFromDey(druability)); + as.setHelmet(item); + } } - } + }catch(IndexOutOfBoundsException ex){} + if(!player.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(is.getAmount()-amount); + is.setAmount(is.getAmount()+4-amount); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), is); player.updateInventory(); } - }else if(sitz.contains(e.getRightClicked())){ + }else if(!armorStand.getHeadPose().equals(new EulerAngle(1.57, .0, .0)) && armorStand.getHelmet().getType().equals(Material.CARPET)){ e.getRightClicked().setPassenger(player); } + }else if(!armorStand.getHeadPose().equals(new EulerAngle(1.57, .0, .0)) && armorStand.getHelmet().getType().equals(Material.CARPET)){ + e.getRightClicked().setPassenger(player); } } } } + + public List getItemListTisch(){ + List items = new ArrayList(); + for(String s : idList){ + ArmorStand as = Utils.getArmorStandAtID(w, s); + if(as.getHelmet()!=null&&as.getHelmet().getType().equals(is.getType())){ + items.add(as.getHelmet()); + } + } + return items; + } - @EventHandler + @EventHandler(priority = EventPriority.NORMAL) public void damage(EntityDamageByEntityEvent e){ + if(e.isCancelled()){return;} if(e.getDamager() instanceof Player){ if(e.getEntity() instanceof ArmorStand){ - if(armorList.contains(e.getEntity())){ + if(idList.contains(e.getEntity().getCustomName())){ delete(true); } } diff --git a/src/de/Ste3et_C0st/Furniture/Objects/tisch.java b/src/de/Ste3et_C0st/Furniture/Objects/indoor/table.java similarity index 56% rename from src/de/Ste3et_C0st/Furniture/Objects/tisch.java rename to src/de/Ste3et_C0st/Furniture/Objects/indoor/table.java index ee58301..10bbcb6 100644 --- a/src/de/Ste3et_C0st/Furniture/Objects/tisch.java +++ b/src/de/Ste3et_C0st/Furniture/Objects/indoor/table.java @@ -1,4 +1,4 @@ -package de.Ste3et_C0st.Furniture.Objects; +package de.Ste3et_C0st.Furniture.Objects.indoor; import java.util.ArrayList; import java.util.List; @@ -7,11 +7,12 @@ import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -22,43 +23,48 @@ import org.bukkit.util.EulerAngle; import de.Ste3et_C0st.Furniture.Main.Utils; import de.Ste3et_C0st.Furniture.Main.main; -public class tisch implements Listener { +public class table implements Listener { - List armorList = new ArrayList(); - ArmorStand armor; - ItemStack is = null; - Location loc = null; - BlockFace b = null; - + private List idList = new ArrayList(); + private ArmorStand armor; + private ItemStack is = null; + private Location loc = null; + private BlockFace b = null; + private String id; + private World w; + public String getID(){return this.id;} public Location getLocation(){return this.loc;} public ItemStack getItemStack(){return this.is;} public BlockFace getBlockFace(){return this.b;} - public tisch(Location loc, Plugin plugin, ItemStack is){ - this.loc = loc; + public table(Location loc, Plugin plugin, ItemStack is, String id){ + this.loc = loc.getBlock().getLocation(); + this.id = id; this.b = Utils.yawToFace(loc.getYaw()); + this.w = loc.getWorld(); Location middle1 = Utils.getCenter(loc); Location middle2 = Utils.getCenter(loc); - Utils.setArmorStand(middle1.add(0,-2.1,0),new EulerAngle(0, 0, 0) , new ItemStack(Material.WOOD_PLATE), false, armorList, null); - Utils.setArmorStand(middle2.add(0,-1.05,0),new EulerAngle(0, 0, 0) , new ItemStack(Material.TRAP_DOOR), false, armorList, null); + Utils.setArmorStand(middle1.add(0,-2.1,0),new EulerAngle(0, 0, 0) , new ItemStack(Material.WOOD_PLATE), false,getID(),idList); + Utils.setArmorStand(middle2.add(0,-1.05,0),new EulerAngle(0, 0, 0) , new ItemStack(Material.TRAP_DOOR), false,getID(),idList); loc.setYaw(0); - ArmorStand as = Utils.setArmorStand(loc.add(.9,0.15,0.3),new EulerAngle(0,.0,.0), is, true, armorList, null); - Utils.setArmorStand(loc.add(0,-.65,.68),new EulerAngle(1.38,.0,.0), new ItemStack(Material.STICK), true, armorList, null); + ArmorStand as = Utils.setArmorStand(loc.add(.9,0.15,0.3),new EulerAngle(0,.0,.0), is, true,getID(),idList); + Utils.setArmorStand(loc.add(0,-.65,.68),new EulerAngle(1.38,.0,.0), new ItemStack(Material.STICK), true,getID(),idList); this.armor = as; plugin.getServer().getPluginManager().registerEvents(this, plugin); main.getInstance().tische.add(this); } - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent e){ + @EventHandler(priority = EventPriority.NORMAL) + private void onInteract(PlayerInteractAtEntityEvent e){ + if(e.isCancelled()){return;} Player player = e.getPlayer(); if(e.getRightClicked() instanceof ArmorStand){ - if(armorList.contains(e.getRightClicked())){ + if(idList.contains(e.getRightClicked().getCustomName())){ e.setCancelled(true); ItemStack is = player.getItemInHand(); - if(is!=null&&!is.getType().isBlock()){ + if(is!=null&&!is.getType().isBlock()||is.getType().equals(Material.AIR)){ if(armor!=null){ - ArmorStand as = (ArmorStand) armorList.get(2); + ArmorStand as = Utils.getArmorStandAtID(w,idList.get(2)); if(armor.getItemInHand()!=null&&!armor.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} as.setItemInHand(is); this.is = is; @@ -72,29 +78,31 @@ public class tisch implements Listener { public void delete(Boolean b){ if(b){ - armorList.get(0).getLocation().getWorld().dropItem(armorList.get(0).getLocation().getBlock().getLocation().add(0, 2, 0), main.getInstance().itemse.tisch); + getLocation().getWorld().dropItem(getLocation(), main.getInstance().crafting.get("table")); if(is!=null && !is.getType().equals(Material.AIR)){ - ArmorStand as = (ArmorStand) armorList.get(2); + ArmorStand as = Utils.getArmorStandAtID(w,idList.get(2)); as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand()); this.is = null; } - for(Entity entity : armorList){ - ArmorStand as = (ArmorStand) entity; - entity.getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); - entity.remove(); + for(String s : idList){ + ArmorStand as = Utils.getArmorStandAtID(w,s); + loc.getWorld().playEffect(loc, Effect.STEP_SOUND, as.getHelmet().getType()); + as.remove(); } + main.getInstance().mgr.deleteFromConfig(getID(), "table"); } this.loc = null; - armorList.clear(); + this.idList.clear(); main.getInstance().tische.remove(this); } - @EventHandler + @EventHandler(priority = EventPriority.NORMAL) public void damage(EntityDamageByEntityEvent e){ + if(e.isCancelled()){return;} if(e.getDamager() instanceof Player){ if(e.getEntity() instanceof ArmorStand){ - if(armorList.contains(e.getEntity())){ + if(idList.contains(e.getEntity().getCustomName())){ delete(true); } } diff --git a/src/de/Ste3et_C0st/Furniture/Objects/largeTable.java b/src/de/Ste3et_C0st/Furniture/Objects/largeTable.java deleted file mode 100644 index 666433c..0000000 --- a/src/de/Ste3et_C0st/Furniture/Objects/largeTable.java +++ /dev/null @@ -1,277 +0,0 @@ -package de.Ste3et_C0st.Furniture.Objects; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.EulerAngle; - -import de.Ste3et_C0st.Furniture.Main.Utils; -import de.Ste3et_C0st.Furniture.Main.main; - -public class largeTable implements Listener { - - List armorList = new ArrayList(); - List location = new ArrayList(); - Location loc = null; - BlockFace b = null; - - public Location getLocation(){return this.loc;} - public BlockFace getBlockFace(){return this.b;} - - public largeTable(Location loc, Plugin plugin, List iL, HashMap tellerItems){ - this.loc = loc; - this.b = Utils.yawToFace(loc.getYaw()); - ItemStack IS1 =null; - ItemStack IS2 =null; - ItemStack IS3 =null; - ItemStack IS4 =null; - - if(tellerItems != null){ - if(tellerItems.containsKey(0)){IS1=tellerItems.get(0);} - if(tellerItems.containsKey(1)){IS2=tellerItems.get(1);} - if(tellerItems.containsKey(2)){IS3=tellerItems.get(2);} - if(tellerItems.containsKey(3)){IS4=tellerItems.get(3);} - } - - Location location = Utils.getCenter(loc.getBlock().getLocation()); - float yaw = Utils.FaceToYaw(this.b); - location = main.getNew(location, this.b, 0.1, 0.28); - location.add(0,.2,0); - Double winkel = 1.57; - int iTems = 0; - for(int x=1; x<=3;x++){ - Location l = null; - l = main.getNew(location, this.b, 0.0, x*-.63); - l.add(0,-1.2,0); - l.setYaw(yaw); - ItemStack iTemStack_1 = new ItemStack(Material.STAINED_GLASS_PANE); - ItemStack iTemStack_2 = new ItemStack(Material.STAINED_GLASS_PANE); - ItemStack iTemStack_3 = new ItemStack(Material.STAINED_GLASS_PANE); - if(iL!=null&&!iL.isEmpty()){ - if(iL.get(iTems)!=null){ - iTemStack_1=iL.get(iTems); - iTems++; - } - if(iL.get(iTems)!=null){ - iTemStack_2=iL.get(iTems); - iTems++; - } - if(iL.get(iTems)!=null){ - iTemStack_3=iL.get(iTems); - iTems++; - } - } - - Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_1, false, armorList,this.location); - l = main.getNew(location, this.b, 0.63, x*-.63); - l.add(0,-1.2,0); - l.setYaw(yaw); - Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_2, false, armorList,this.location); - l = main.getNew(location, this.b, 1.26, x*-.63); - l.add(0,-1.2,0); - l.setYaw(yaw); - Utils.setArmorStand(l, new EulerAngle(winkel, 0, 0), iTemStack_3, false, armorList,this.location); - } - - Location middle = Utils.getCenter(armorList.get(0).getLocation()); - Location mitteTisch = Utils.getCenter(armorList.get(4).getLocation().getBlock().getLocation()); - middle.add(0, -.9, 0); - Location feet1 = main.getNew(middle, this.b, -.2, .1); - Location feet2 = main.getNew(middle, this.b, -.2, -1.3); - Location feet3 = main.getNew(middle, this.b, 1.1, .1); - Location feet4 = main.getNew(middle, this.b, 1.1, -1.3); - - - double hight = .67; - - Location t1 = main.getNew(mitteTisch, this.b, -.95, .4).add(0,hight,0); - Location t2 = main.getNew(mitteTisch, this.b, -.4, -.92).add(0,hight,0); - Location t3 = main.getNew(mitteTisch, this.b, .92, -.36).add(0,hight,0); - Location t4 = main.getNew(mitteTisch, this.b, .4, .92).add(0,hight,0); - - float yaw1 = yaw; - float yaw2 = yaw1-90; - float yaw3 = yaw2-90; - float yaw4 = yaw3-90; - - t1.setYaw(yaw1); - t2.setYaw(yaw2); - t3.setYaw(yaw3); - t4.setYaw(yaw4); - - feet1.setYaw(yaw); - feet2.setYaw(yaw); - feet3.setYaw(yaw); - feet4.setYaw(yaw); - - Utils.setArmorStand(feet1, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, armorList,null); - Utils.setArmorStand(feet2, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, armorList,null); - Utils.setArmorStand(feet3, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, armorList,null); - Utils.setArmorStand(feet4, new EulerAngle(-1.75, 0, 0), new ItemStack(Material.BONE), true, armorList,null); - Utils.setArmorStand(t1, new EulerAngle(0,0,0), IS1, true, armorList,null); - Utils.setArmorStand(t2, new EulerAngle(0,0,0), IS2, true, armorList,null); - Utils.setArmorStand(t3, new EulerAngle(0,0,0), IS3, true, armorList,null); - Utils.setArmorStand(t4, new EulerAngle(0,0,0), IS4, true, armorList,null); - - for(Entity e : armorList){ - ArmorStand armor = (ArmorStand) e; - armor.setVisible(false); - armor.setGravity(false); - } - - plugin.getServer().getPluginManager().registerEvents(this, plugin); - main.getInstance().tische2.add(this); - } - - public void delete(boolean b){ - if(b){ - armorList.get(0).getLocation().getWorld().dropItem(armorList.get(0).getLocation().getBlock().getLocation().add(0, 1, 0), main.getInstance().itemse.tisch2); - for(Entity entity : armorList){ - ArmorStand as = (ArmorStand) entity; - entity.getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, as.getHelmet().getType()); - entity.remove(); - } - } - location.clear(); - armorList.clear(); - main.getInstance().sofas.remove(this); - } - - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent e){ - Player player = e.getPlayer(); - if(e.getRightClicked() instanceof ArmorStand){ - if(armorList.contains(e.getRightClicked())){ - e.setCancelled(true); - ItemStack is = player.getItemInHand(); - if(is!=null){ - if(is.getType().equals(Material.INK_SACK)){ - Short druability = is.getDurability(); - Integer amount = is.getAmount(); - if(amount>armorList.size() || player.getGameMode().equals(GameMode.CREATIVE)){amount=armorList.size();} - List list = new ArrayList(); - for(Entity entity : armorList){ - if(entity instanceof ArmorStand){ - ArmorStand as = (ArmorStand) entity; - ItemStack item = as.getHelmet(); - if(item.getDurability() != main.getFromDey(druability)){ - list.add(entity); - } - } - } - - for(int i = 0; i<=amount-1;i++){ - Entity entity = list.get(i); - if(entity instanceof ArmorStand){ - ArmorStand as = (ArmorStand) entity; - ItemStack item = as.getHelmet(); - item.setDurability(main.getFromDey(druability)); - as.setHelmet(item); - } - } - if(!player.getGameMode().equals(GameMode.CREATIVE)){ - is.setAmount(is.getAmount()-amount); - player.getInventory().setItem(player.getInventory().getHeldItemSlot(), is); - player.updateInventory(); - } - }else if(!is.getType().isBlock()){ - Integer i = armorList.size(); - if(armorList.get(3).equals(e.getRightClicked())){ - i-=4; - ArmorStand as = (ArmorStand) armorList.get(i); - if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} - as.setItemInHand(is); - } - if(armorList.get(7).equals(e.getRightClicked())){ - i-=3; - ArmorStand as = (ArmorStand) armorList.get(i); - if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} - as.setItemInHand(is); - } - if(armorList.get(5).equals(e.getRightClicked())){ - i-=2; - ArmorStand as = (ArmorStand) armorList.get(i); - if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} - as.setItemInHand(is); - } - if(armorList.get(1).equals(e.getRightClicked())){ - i-=1; - ArmorStand as = (ArmorStand) armorList.get(i); - if(as.getItemInHand()!=null&&!as.getItemInHand().getType().equals(Material.AIR)){as.getLocation().getWorld().dropItem(as.getLocation(), as.getItemInHand());} - as.setItemInHand(is); - } - } - } - } - } - } - - @EventHandler - public void damage(EntityDamageByEntityEvent e){ - if(e.getDamager() instanceof Player){ - if(e.getEntity() instanceof ArmorStand){ - if(armorList.contains(e.getEntity())){ - delete(true); - } - } - } - } - - @EventHandler - public void onWaterFlow(BlockFromToEvent e){ - Location locTo = e.getToBlock().getLocation(); - if(location!=null && !location.isEmpty()){ - if(location.contains(locTo) || location.contains(locTo.add(0,-0.5,0))){ - e.setCancelled(true); - } - } - } - - public List getItemListTisch(){ - List items = new ArrayList(); - for(int i = 0; i<=8;i++){ - items.add((((ArmorStand)armorList.get(i)).getHelmet())); - } - return items; - } - - public HashMap getTeller(){ - HashMap teller = new HashMap(); - for(int i = 0;i<=3;i++){ - try{ - teller.put(i, ((ArmorStand) armorList.get(armorList.size()-1-i)).getItemInHand()); - }catch(NullPointerException e){ - teller.put(i, new ItemStack(Material.AIR)); - } - } - return teller; - } - - /* - @EventHandler - public void onHit(PlayerMoveEvent e){ - Player p = e.getPlayer(); - if(!p.isInsideVehicle() && location!=null){ - if(location.contains(e.getTo().getBlock().getLocation()) || location.contains(e.getTo().getBlock().getLocation().add(0,-1,0))){ - p.teleport(e.getFrom()); - } - } - } - */ -} diff --git a/src/plugin.yml b/src/plugin.yml index 7b2b0e6..1d61b7a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,12 +1,12 @@ name: Furniture -version: 0.1 +version: 1.5 description: DiceEquipment author: Ste3et_C0st website: http://dicecraft.de - +softdepend: [Vault] main: de.Ste3et_C0st.Furniture.Main.main commands: - Furniture: - description: test + furniture: + description: DiceEaster Egg Command usage: / \ No newline at end of file