Hello I have a problem. In the event that I put Piston_base or NOTE_Block I Have The global inventar these chests. I need that every chest had its inventory. How to do it? main class Code:java public void onEnable() { inv = Bukkit.createInventory(null, 27, "§lBonus Chest"); System.out.println("[BonusChest] Plugin zapnut"); PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new me.Hugo.Listener.ChestListener(), this); } public void onDisable() { System.out.println("[BonusChest] Plugin vypnut"); } Chest class Code:java public class ChestListener implements Listener{ @EventHandler public void onClick(PlayerInteractEvent e) { Player p = e.getPlayer(); if ((p.hasPermission("playerchest.use")) || (p.isOp())) { if ((main.chestworld.contains(p.getLocation().getWorld().getName())) && (e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.PISTON_BASE)) { p.openInventory(main.inv); } } else { p.sendMessage(ChatColor.translateAlternateColorCodes('&', main.prefix) + " " + ChatColor.translateAlternateColorCodes('&', main.nopermschest)); } if ((p.hasPermission("vipchest.use")) || (p.isOp())) { if ((main.chestworld.contains(p.getLocation().getWorld().getName())) && (e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.NOTE_BLOCK)) { p.openInventory(main.inv); } } else { p.sendMessage(ChatColor.translateAlternateColorCodes('&', main.prefix) + " " + ChatColor.translateAlternateColorCodes('&', main.nopermschest)); } }}
For saving/loading inventories to files: Code:java public void createFile(Location loc) {int x = loc.getX();int y = loc.getY();int z = loc.getZ(); File file = new File(getDataFolder() + "/chests", x+","+y+","+z+ ".yml");if (!file.exists()) {FileConfiguration config = YamlConfiguration.loadConfiguration(file); config.set("Items.0", new ItemStack(Material.AIR)); try {config.save(file);} catch(Exception e) {}}} public boolean exists(Location loc) {int x = loc.getX();int y = loc.getY();int z = loc.getZ();return new File(getDataFolder() + "/chests", x+","+y+","+z+ ".yml").exists();} public Inventory getInventory(Location loc) {int x = loc.getX();int y = loc.getY();int z = loc.getZ(); File file = new File(getDataFolder() + "/chests", x+","+y+","+z+ ".yml");if (!file.exists()) return null; FileConfiguration config = YamlConfiguration.loadConfiguration(file); Inventory inv = Bukkit.createInventory(null, 27, "Chest");for (String key : config.getConfigurationSection("Items").getKeys(false)) {try {inv.setItem(Integer.parseInt(key),config.getItemStack("Items." + key));} catch (Exception e) { } return inv;} public void saveChest(Location loc) {int x = loc.getX();int y = loc.getY();int z = loc.getZ(); if(exists(loc)) {File file = new File(getDataFolder() + "/chests", x+","+y+","+z+ ".yml");FileConfiguration config = YamlConfiguration.loadConfiguration(file);Inventory inv = getInventory(loc); for(int i = 0; i < 27; i++) {if(loc.getItem(i) == 0) {config.set("Items." + i, null);} else {config.set("Items." + i, e.getInventory().getItem(i));}} try {config.save(file);} catch (Exception ex) { }}}
FisheyLP 1) Please don't spoon-feed 2) See the File(File, String) constructor 3) Is that even what the OP is asking?
then add a HashMap<Location, Inventory> to store the locations of the piston_base and create a inventory for it
FisheyLP while(true) is an infinite loop, for(int i = 0; i > -1; i++) is not. Not sure if that's an error on CraftCreeper6 's part or intended
FisheyLP AdamQpzm I think it's more a factor of Signatures are not supposed to be serious. EDIT: What does my Signature have to do with my Profile Picture?
FisheyLP Once it hits the maximum value, it restarts from the minimum value, which is less than -1. It's a large amount of iterations, but finite.
that would take years to get the maximum value ^^ and i dont think that much people runs programs / plugins for more than a day without closing it
FisheyLP I think you'll find that it wont take years, it will take a couple of seconds depending on how much RAM your server has...
Would depend on what the methods actually do. If it's something simple, then it definitely wouldn't take years. CraftCreeper6 It would take seconds if essentially nothing happened with the methods, but we don't know what these methods actually do. It would also be irrelevant the amount of RAM.
CraftCreeper6 Yes, a lack of RAM can cause a computer to crash, but it doesn't really affect performance in this case. It'll either be able to run... or it won't. Processor will be the bottleneck, not RAM.
AdamQpzm Fair enough, I used to have 2 GB RAM and my PC crashed when I tried to run a program. I upgraded
i have a very slow computer so it would take years for me ^^ int goes from -2^33 to 2^33 (it is -8589934592 to 8589934592) EDIT by Moderator: merged posts, please use the edit button instead of double posting.