Searching a MineZ chest refiller :).

Discussion in 'Archived: Plugin Requests' started by Scrollzz, Dec 30, 2012.

  1. I am searching a plugin that works like the MineZ one. Not like "Loot" or any other. I want it so all chests in a world refills with random things typed into an config. Does anyone know one like that?
    Or can anyone make one :)?
     
  2. Offline

    CurtMantis

    erm, it's against the forum rules to offer money as far as i know...
    I don't know of any plugin that does what you're asking for.. but I use TreasureChests, it's really easy to set up.
     
  3. No one knows a plugin like that?
     
  4. Offline

    lol768

    Monetary offers are not permitted.
     
  5. Offline

    youngbawss22

    You think anybody reads the rules anymore? heh...
     
    1mpre55 likes this.
  6. If any dev wants to do this here is a little help (works but is a little bit of a mess :D)
    Show Spoiler
    Code:java
    1. package me.mncat77.mnlootchests;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map;
    5. import java.util.Random;
    6. import net.minecraft.server.NBTTagCompound;
    7. import net.minecraft.server.NBTTagList;
    8. import net.minecraft.server.NBTTagString;
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.Location;
    11. import org.bukkit.Material;
    12. import org.bukkit.block.Block;
    13. import org.bukkit.block.BrewingStand;
    14. import org.bukkit.block.Chest;
    15. import org.bukkit.block.Dispenser;
    16. import org.bukkit.block.Furnace;
    17. import org.bukkit.command.Command;
    18. import org.bukkit.command.CommandSender;
    19. import org.bukkit.craftbukkit.inventory.CraftItemStack;
    20. import org.bukkit.enchantments.Enchantment;
    21. import org.bukkit.plugin.java.JavaPlugin;
    22.  
    23. public class MnLootChests extends JavaPlugin{
    24.  
    25. public Map<String, String> ChestItemArg = new HashMap<String, String>();
    26.  
    27. @Override
    28. public void onDisable() {
    29.  
    30.  
    31.  
    32. }
    33.  
    34. @Override
    35. public void onEnable() {
    36.  
    37.  
    38. loadConfig();
    39. int regenerateChestsTaskID = this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    40.  
    41. public void run(){
    42.  
    43. int ChestCount = Integer.parseInt(getConfig().getString("ChestCount"));
    44. for(int i=1; i <= ChestCount; i++){
    45.  
    46. String locs = (String)getConfig().get("Chest" + i + ".Coordinates");
    47. String[] loc = locs.split(",");
    48. Location location = new Location(Bukkit.getWorld("world"),Double.parseDouble(loc[0]),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]));
    49.  
    50. boolean regenChest = true;
    51.  
    52. for(int j=0; (j+1) <= Bukkit.getOnlinePlayers().length; j++){
    53. if(Bukkit.getOnlinePlayers()[j].getLocation().distance(location) < 53){
    54. regenChest = false;
    55. break;
    56. }
    57. }
    58. if(regenChest){
    59. int ChestType = getConfig().getInt("Chest" + i + ".ChestType");
    60. int Face = getConfig().getInt("Chest" + i + ".Face");
    61. Block block = location.getBlock();
    62. if(block.getTypeId() == 54){
    63. Chest chest = (Chest)location.getBlock().getState();
    64. chest.getBlockInventory().clear();
    65. }
    66. else if(block.getTypeId() == 61){
    67. Furnace furnace = (Furnace)location.getBlock().getState();
    68. furnace.getInventory().clear();
    69. }
    70. else if(block.getTypeId() == 117){
    71. BrewingStand brewingstand = (BrewingStand)location.getBlock().getState();
    72. brewingstand.getInventory().clear();
    73. }
    74. else if(block.getTypeId() == 23){
    75. Dispenser dispenser = (Dispenser)location.getBlock().getState();
    76. dispenser.getInventory().clear();
    77. }
    78. block.setType(Material.AIR);
    79. block.setType(Material.CHEST);
    80. block.setData((byte)Face);
    81. Chest chest = (Chest)location.getBlock().getState();
    82. CraftItemStack[] items = randomizeChest(ChestType);
    83. chest.getBlockInventory().setContents(items);
    84. }
    85. }
    86. }
    87.  
    88.  
    89. }, 20L, 1200L);
    90.  
    91. int fillFurnacesTaskID = this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    92.  
    93. public void run(){
    94.  
    95. int FurnaceCount = Integer.parseInt(getConfig().getString("FurnaceCount"));
    96. for(int i=1; i <= FurnaceCount; i++){
    97.  
    98. String locs = (String)getConfig().get("Furnace" + i + ".Coordinates");
    99. String[] loc = locs.split(",");
    100. Location location = new Location(Bukkit.getWorld("world"),Double.parseDouble(loc[0]),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]));
    101.  
    102. boolean fillFurnace = true;
    103.  
    104. for(int j=0; (j+1) <= Bukkit.getOnlinePlayers().length; j++){
    105. if(Bukkit.getOnlinePlayers()[j].getLocation().distance(location) < 53){
    106. fillFurnace = false;
    107. break;
    108. }
    109. }
    110. if(fillFurnace){
    111. Block block = location.getBlock();
    112. if(block.getTypeId() == 54){
    113. Chest chest = (Chest)location.getBlock().getState();
    114. chest.getBlockInventory().clear();
    115. }
    116. else if(block.getTypeId() == 61){
    117. Furnace furnace = (Furnace)location.getBlock().getState();
    118. furnace.getInventory().clear();
    119. }
    120. else if(block.getTypeId() == 117){
    121. BrewingStand brewingstand = (BrewingStand)location.getBlock().getState();
    122. brewingstand.getInventory().clear();
    123. }
    124. else if(block.getTypeId() == 23){
    125. Dispenser dispenser = (Dispenser)location.getBlock().getState();
    126. dispenser.getInventory().clear();
    127. }
    128. int Face = getConfig().getInt("Furnace" + i + ".Face");
    129. block.setType(Material.AIR);
    130. block.setType(Material.FURNACE);
    131. block.setData((byte)Face);
    132. Furnace furnace = (Furnace)location.getBlock().getState();
    133. CraftItemStack fuel = randomizeFurnace();
    134. furnace.getInventory().setFuel(fuel);
    135. }
    136. }
    137. }
    138.  
    139.  
    140. }, 20L, 1200L);
    141. }
    142.  
    143. @Override
    144. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    145.  
    146. if(command.getName().equalsIgnoreCase("chest")){
    147.  
    148. String locs = (String)this.getConfig().get("Chest" + 1 + ".Coordinates");
    149. String[] loc = locs.split(",");
    150. Location location = new Location(Bukkit.getWorld("world"),Double.parseDouble(loc[0]),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]));
    151. Block block = location.getBlock();
    152. if(block.getTypeId() == 54){
    153. Chest chest = (Chest)location.getBlock().getState();
    154. chest.getBlockInventory().clear();
    155. }
    156. else if(block.getTypeId() == 61){
    157. Furnace furnace = (Furnace)location.getBlock().getState();
    158. furnace.getInventory().clear();
    159. }
    160. else if(block.getTypeId() == 117){
    161. BrewingStand brewingstand = (BrewingStand)location.getBlock().getState();
    162. brewingstand.getInventory().clear();
    163. }
    164. else if(block.getTypeId() == 23){
    165. Dispenser dispenser = (Dispenser)location.getBlock().getState();
    166. dispenser.getInventory().clear();
    167. }
    168. block.setType(Material.AIR);
    169. block.setType(Material.CHEST);
    170. Chest chest = (Chest)location.getBlock().getState();
    171. CraftItemStack[] items = randomizeChest(1);
    172. chest.getBlockInventory().setContents(items);
    173. //chest.getBlockInventory().addItem(getItemStack(303, 1, "Flak Vest", "This will protect you from skeleton.§kasd", Enchantment.PROTECTION_PROJECTILE, 4));
    174. }
    175.  
    176. return true;
    177.  
    178. }
    179.  
    180. private CraftItemStack getItemStack(int ItemID, int durability, int count, String name, String lore, Enchantment ench, int enchLvl){
    181.  
    182. CraftItemStack item = new CraftItemStack(ItemID, count);
    183.  
    184. if(!name.isEmpty() && lore.isEmpty()){
    185. NBTTagCompound tag = new NBTTagCompound();
    186. NBTTagCompound display = new NBTTagCompound();
    187. tag.setCompound("display", display);
    188. display.setString("Name", name);
    189. item.getHandle().tag = tag;
    190. }
    191.  
    192. if(!lore.isEmpty() && !name.isEmpty()){
    193. NBTTagCompound tag = new NBTTagCompound();
    194. NBTTagCompound display = new NBTTagCompound();
    195. tag.setCompound("display", display);
    196. NBTTagList list = new NBTTagList();
    197. list.add(new NBTTagString("", lore));
    198. display.set("Lore", list);
    199. item.getHandle().tag = tag;
    200. }
    201.  
    202. if(!(name.isEmpty() && lore.isEmpty())){
    203. NBTTagCompound tag = new NBTTagCompound();
    204. NBTTagCompound display = new NBTTagCompound();
    205. tag.setCompound("display", display);
    206. display.setString("Name", name);
    207. NBTTagList list = new NBTTagList();
    208. list.add(new NBTTagString("", lore));
    209. display.set("Lore", list);
    210. item.getHandle().tag = tag;
    211.  
    212. }
    213.  
    214. if((ench != null) && (enchLvl != 0)){
    215. item.addUnsafeEnchantment(ench, enchLvl);
    216. }
    217. item.setDurability((short)durability);
    218.  
    219. return item;
    220. }
    221.  
    222. private void loadConfig(){
    223.  
    224. int ChestTypesCount = Integer.parseInt(this.getConfig().getString("ChestTypesCount"));
    225. for(int i=1; i<=ChestTypesCount; i++){
    226. int ItemsCount = Integer.parseInt(this.getConfig().getString("ChestType" + i + ".ItemsCount"));
    227. for(int j=1; j<=ItemsCount; j++){
    228. String args = this.getConfig().getString("ChestType" + i + ".Item" + j);
    229. String[] split = args.split(";");
    230. for(int k=0; k < split.length; k++){
    231. String a = split[k];
    232. ChestItemArg.put(i + "," + j + "," + (k+1), a);
    233. }
    234. }
    235. }
    236.  
    237. }
    238.  
    239. private CraftItemStack[] randomizeChest(int n){
    240. int im = 0;
    241. int ItemsCount = Integer.parseInt(this.getConfig().getString("ChestType" + n + ".ItemsCount"));
    242. CraftItemStack[] items = new CraftItemStack[27];
    243. Random randomGenerator = new Random();
    244. do{for(int i=1;i<=ItemsCount;i++){
    245. int s = randomGenerator.nextInt(26);
    246. int random = randomGenerator.nextInt(100)+1;
    247. if((Integer.parseInt(ChestItemArg.get(n + "," + i + "," + 8))) >= random){
    248. items[S] = getItemStack(Integer.parseInt(ChestItemArg.get(n + "," + i + "," + 1)), Integer.parseInt(ChestItemArg.get(n + "," + i + "," + 2)), Integer.parseInt(ChestItemArg.get(n + "," + i + "," + 3)),ChestItemArg.get(n + "," + i + "," + 4),ChestItemArg.get(n + "," + i + "," + 5), Enchantment.getByName(ChestItemArg.get(n + "," + i + "," + 6)), Integer.parseInt(ChestItemArg.get(n + "," + i + "," + 7)));[/S]
    249. [S] im++;[/S]
    250. [S] }[/S]
    251. [S] }}while(im==0);[/S]
    252.  
    253. [S] return items;[/S]
    254. [S] }[/S]
    255.  
    256. [S] private CraftItemStack randomizeFurnace(){[/S]
    257. [S] CraftItemStack fuel;[/S]
    258. [S] Random randomGenerator = new Random();[/S]
    259. [S] int random = randomGenerator.nextInt(6);[/S]
    260. [S] switch(random){[/S]
    261. [S] case 0:[/S]
    262. [S] fuel = new CraftItemStack(263,randomGenerator.nextInt(3)+1);[/S]
    263. [S] break;[/S]
    264. [S] case 1:[/S]
    265. [S] fuel = new CraftItemStack(263,randomGenerator.nextInt(3)+1,(short)1);[/S]
    266. [S] break;[/S]
    267. [S] case 2:[/S]
    268. [S] fuel = new CraftItemStack(280,randomGenerator.nextInt(1)+1);[/S]
    269. [S] break;[/S]
    270. [S] case 3:[/S]
    271. [S] fuel = new CraftItemStack(17,randomGenerator.nextInt(2)+1,(short)randomGenerator.nextInt(3));[/S]
    272. [S] break;[/S]
    273. [S] case 4:[/S]
    274. [S] fuel = new CraftItemStack(5,randomGenerator.nextInt(2)+1,(short)randomGenerator.nextInt(3));[/S]
    275. [S] break;[/S]
    276. [S] default:[/S]
    277. [S] fuel = new CraftItemStack(0);[/S]
    278. [S] }[/S]
    279. [S] return fuel;[/S]
    280. [S] }[/S]
    281.  
    282.  
    283. [S]}[/S]
    284.  
    285. [S][/S]

    Config would look like this:
    Show Spoiler
    FurnaceCount: 2
    Show Spoiler

    Furnace1:
    Coordinates: 73,64,193
    Face: 0

    Furnace2:
    Coordinates: 78,64,204
    Face: 2

    ChestTypesCount: 1
    ChestType1:
    ItemsCount: 5
    Item1: 303;5;1;Flak Vest;This will protect you from skeleton.§kasd;PROTECTION_PROJECTILE;4;20
    Item2: 57;1;2;DIAMONDBLOCKS!!!;You will never get this...;ARROW_DAMAGE;0;5
    Item3: 309;90;1;Heavy Booties;;ARROW_DAMAGE;0;30
    Item4: 34;1;1;Wooden Shield;;ARROW_DAMAGE;0;25
    Item5: 294;20;1;Wand;;DAMAGE_ALL;30;15

    ChestCount: 2
    Chest1:
    Coordinates: 100,64,201
    ChestType: 1
    Face: 0

    Chest2:
    ChestType: 1
    Coordinates: 84,64,217
    Face: 0


    Edit: Why are the words stroke? lol...
    ... Why are there three spoilers now.. What is going on...
     
  7. Can you maybe make something like that? Please send me a PM :).
     
  8. That is basically it....
     
  9. What is it? The code? I dont know anything about it. Can you please make it a jar if so :confused:.
     
  10. Offline

    ThunderWaffeMC

    Don't bump more than once. And, use ChestRestock. Also change the monetary offer. Why do you ignore all the warnings?
     

Share This Page