Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.66 KB | None | 0 0
  1. //IN YOUR ON ENABLE YOU MUST REGISTER THE TIMER CLASS.
  2. private int iTimer = 0;
  3.  
  4. @Override
  5. public void onEnable() {
  6. System.out.println("[IceCream] - Roaming ShopKeeper Plugin by dNiym ENABLED.");
  7. this.iTimer = getServer().getScheduler().scheduleSyncRepeatingTask(this, new iceCreamTimer(this), 20l, 20l);
  8.  
  9. }
  10.  
  11. @Override
  12. public void onDisable() {
  13. iceCreamTimer.clear();
  14. this.getServer().getScheduler().cancelTask(this.iTimer);
  15. this.getServer().getScheduler().cancelTasks(this);
  16. }
  17.  
  18.  
  19. //TIMER CLASS
  20. package Timers;
  21.  
  22. import java.io.File;
  23. import java.util.ArrayList;
  24. import java.util.HashSet;
  25. import java.util.List;
  26. import java.util.Set;
  27. import java.util.UUID;
  28.  
  29. import org.bukkit.ChatColor;
  30. import org.bukkit.Effect;
  31. import org.bukkit.Location;
  32. import org.bukkit.Material;
  33. import org.bukkit.OfflinePlayer;
  34. import org.bukkit.Particle;
  35. import org.bukkit.World;
  36. import org.bukkit.block.Block;
  37. import org.bukkit.entity.Entity;
  38. import org.bukkit.entity.EntityType;
  39. import org.bukkit.entity.Item;
  40. import org.bukkit.entity.Player;
  41. import org.bukkit.inventory.Inventory;
  42. import org.bukkit.inventory.ItemFlag;
  43. import org.bukkit.inventory.ItemStack;
  44. import org.bukkit.inventory.PlayerInventory;
  45. import org.bukkit.inventory.meta.ItemMeta;
  46. import org.bukkit.inventory.meta.SpawnEggMeta;
  47. import org.bukkit.material.MonsterEggs;
  48.  
  49. import com.sk89q.worldedit.CuboidClipboard;
  50. import com.sk89q.worldedit.EditSession;
  51. import com.sk89q.worldedit.MaxChangedBlocksException;
  52. import com.sk89q.worldedit.Vector;
  53. import com.sk89q.worldedit.bukkit.BukkitWorld;
  54. import com.sk89q.worldguard.bukkit.WGBukkit;
  55. import com.sk89q.worldguard.protection.managers.RegionManager;
  56. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  57. import com.xxmicloxx.NoteBlockAPI.NBSDecoder;
  58. import com.xxmicloxx.NoteBlockAPI.RadioSongPlayer;
  59. import com.xxmicloxx.NoteBlockAPI.Song;
  60. import com.xxmicloxx.NoteBlockAPI.SongPlayer;
  61.  
  62. import de.slikey.effectlib.effect.SmokeEffect;
  63. import de.slikey.effectlib.util.ParticleEffect;
  64. import iceCream.iceCreamMan;
  65. import io.netty.util.internal.ThreadLocalRandom;
  66.  
  67. import items.RareItem;
  68. import items.mcIconMenu;
  69. import mobDrops.gear;
  70. import net.citizensnpcs.api.CitizensAPI;
  71. import net.citizensnpcs.api.event.DespawnReason;
  72. import net.citizensnpcs.api.event.NPCRightClickEvent;
  73. import net.citizensnpcs.api.npc.NPC;
  74.  
  75. import net.citizensnpcs.npc.skin.SkinnableEntity;
  76. import net.minecraft.server.v1_12_R1.EntityTypes;
  77. import net.minecraft.server.v1_12_R1.TileEntity;
  78.  
  79.  
  80. public class iceCreamTimer implements Runnable {
  81. private iceCreamMan plugin;
  82. private int songCount = 0;
  83. private Song s = null;
  84. private SongPlayer sp = null;
  85. private SmokeEffect efx = null;
  86. private Long efxDelay = 0L;
  87. private long spawnDelay = 0L;
  88. private boolean spawned = false;
  89. private NPC npc;
  90. private Set<Material> validBlocks = new HashSet<Material>();
  91.  
  92. private static World w;
  93. private List<Block> ceil = new ArrayList<Block>();
  94. // private Entity cart = null;
  95. public static iceCreamTimer instance;
  96. public static boolean forceSpawn = false;
  97. private Long timeout = 0L;
  98. private boolean named = false;
  99. private long nameDelay = 0L;
  100. private PlayerInventory inventory;
  101. private mcIconMenu menu;
  102. private Set<Player> viewers = new HashSet<Player>();
  103.  
  104.  
  105. public iceCreamTimer(iceCreamMan iceCream) {
  106. this.plugin = iceCream;
  107.  
  108. this.validBlocks.add(Material.GRASS);
  109. this.validBlocks.add(Material.SAND);
  110. this.validBlocks.add(Material.WOOD);
  111. iceCreamTimer.w = plugin.getServer().getWorld("skyblock");
  112. this.ceil = getCeiling(w);
  113. iceCreamTimer.instance = this;
  114. }
  115.  
  116. @Override
  117. public void run() {
  118. if(plugin.getServer().getOnlinePlayers().size() > 0) {
  119. if(this.spawned && this.named)
  120. {
  121. //do the song
  122. if(this.s == null)
  123. this.s = NBSDecoder.parse(new File("plugins/IceCream/icecreamsong.nbs"));
  124.  
  125. if(this.efxDelay <= System.currentTimeMillis() && this.songCount < 3) {
  126.  
  127. this.efxDelay = System.currentTimeMillis() + 500l;
  128. Location el = this.npc.getEntity().getLocation().clone().add(0,6,2);
  129. // el.getWorld().spawnParticle(Particle.NOTE, el, 10);
  130. Double r1 = ThreadLocalRandom.current().nextDouble(-0.5,0.5);
  131. Double r2 = ThreadLocalRandom.current().nextDouble(-0.5,0.5);
  132.  
  133. el.getWorld().spawnParticle(Particle.NOTE, el, 5, r1, 0, r2);
  134. }
  135.  
  136. if((this.sp == null || !this.sp.isPlaying()) && this.songCount < 3)
  137. {
  138.  
  139.  
  140. this.sp = new RadioSongPlayer(s);
  141. this.songCount ++;
  142. // sp.setAutoDestroy(true);
  143. for(Player p:this.plugin.getServer().getOnlinePlayers())
  144. sp.addPlayer(p);
  145.  
  146. sp.setPlaying(true);
  147.  
  148. }
  149. }
  150.  
  151. if(iceCreamMan.isFirstRun())
  152. {
  153. iceCreamMan.setFirstRun(false);
  154. int minTime = plugin.getConfig().getInt("Settings.MinutesBetweenSpawnsMin");
  155. int maxTime = plugin.getConfig().getInt("Settings.MinutesBetweenSpawnsMax");
  156. int rTime = ThreadLocalRandom.current().nextInt(minTime,maxTime);
  157.  
  158. this.spawnDelay = System.currentTimeMillis() + (rTime * 60 * 1000);
  159.  
  160. } else if(forceSpawn) {
  161. forceSpawn = false;
  162. this.spawnDelay = 0L;
  163. }
  164. if(System.currentTimeMillis() >= this.spawnDelay && !this.spawned) {
  165.  
  166. Location l = new Location(w, 974.5, 163, -679);
  167. //Location l = findSafeLoc(this.ceil);
  168.  
  169. for(Player p:this.plugin.getServer().getOnlinePlayers())
  170. p.sendMessage(ChatColor.GREEN + "Oh snap! The " +ChatColor.AQUA + "Ice Cream Man " + ChatColor.GREEN + "Has arrived somewhere in spawn!");
  171.  
  172. spawnTruck();
  173.  
  174.  
  175. for(Player p:l.getWorld().getPlayers()) {
  176. if(p.getLocation().distance(l) <= 6) {
  177. p.teleport(p.getLocation().add(0,6,0));
  178. p.sendMessage(ChatColor.GREEN + "Oops the Ice Cream man's truck almost ran you over!");
  179. }
  180.  
  181. }
  182.  
  183.  
  184.  
  185. this.setNpc(CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, UUID.fromString("3a8e7630-fa7f-4193-b030-69f380c40768"), 2, "Ice Cream Man"));
  186. this.getNpc().spawn(l);
  187. // System.out.println("Npc spawned at: " + this.cart.getLocation().toString());
  188.  
  189. this.spawned = true;
  190.  
  191. this.timeout = (long) (plugin.getConfig().getInt("Settings.MinutesUntilDespawn") * 60 * 1000) + System.currentTimeMillis();
  192.  
  193. this.nameDelay = System.currentTimeMillis() + 500;
  194.  
  195.  
  196. }
  197.  
  198. if(this.getNpc() != null && this.getNpc().isSpawned() && !this.named && System.currentTimeMillis() >= this.nameDelay)
  199. {
  200.  
  201. this.getNpc().data().set(NPC.PLAYER_SKIN_USE_LATEST, false);
  202. this.getNpc().data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, "hippiebeak");
  203. SkinnableEntity skinnable = getNpc().getEntity() instanceof SkinnableEntity ? (SkinnableEntity) getNpc().getEntity()
  204. : null;
  205. if (skinnable != null) {
  206. skinnable.setSkinName("HippieBeak", true);
  207. }
  208. this.named = true;
  209. // Minecart mcart = (Minecart) this.cart;
  210. // mcart.setMaxSpeed(0);
  211. // mcart.setGlowing(true);
  212. this.getNpc().setProtected(true);
  213. // mcart.addPassenger(this.getNpc().getEntity());
  214. }
  215. }
  216. if(this.spawned && this.named && System.currentTimeMillis() >= this.timeout)
  217. {
  218. /*
  219. if(this.getNpc() != null) {
  220. this.getNpc().setProtected(false);
  221. this.getNpc().despawn();
  222. this.getNpc().destroy();
  223.  
  224. }
  225. if(this.cart != null)
  226. this.cart.remove();
  227.  
  228. this.menu.destroy();
  229. this.menu = null;
  230. this.named = false;
  231.  
  232. this.spawned = false;
  233. this.spawnDelay = System.currentTimeMillis() + (plugin.getConfig().getInt("Settings.MinutesBetweenSpawns") * 60 * 1000);
  234. for(Player p:this.plugin.getServer().getOnlinePlayers())
  235. p.sendMessage(ChatColor.GREEN + "The " +ChatColor.AQUA + "Ice Cream Man " + ChatColor.GREEN + "Has moved along! Better luck next time!");
  236. */
  237. this.remove();
  238. }
  239. }
  240.  
  241. public static void spawnTruck()
  242. {
  243. RegionManager rm = WGBukkit.getRegionManager(w);
  244.  
  245. //ProtectedRegion region = rm.getRegion("b_arena_area");
  246. ProtectedRegion region = rm.getRegion("IceCream");
  247. Vector minx = region.getMinimumPoint();
  248. boolean empty = true;
  249.  
  250. if(empty == true)
  251. {
  252.  
  253. File file = new File("plugins/WorldEdit/schematics/icecream.schematic");
  254. World world = w;
  255. int aX = (int) minx.getX();
  256. int aY = (int) minx.getY();
  257. int aZ = (int) minx.getZ();
  258.  
  259. BukkitWorld BW = new BukkitWorld(world);
  260.  
  261.  
  262. @SuppressWarnings("deprecation")
  263. EditSession es = new EditSession(BW, 2000000);
  264.  
  265. // Alternatives: ( class com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard,class com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat )
  266.  
  267. CuboidClipboard c =null;
  268. try {
  269. c = CuboidClipboard.loadSchematic(file);
  270. } catch (Exception e) {
  271. // TODO Auto-generated catch block
  272. System.out.println("[IceCream] Could not load the IceCream.schematic!! " );
  273. e.printStackTrace();
  274. }
  275. if (c == null)
  276. return;
  277. try {
  278. c.place(es, minx, false);
  279. } catch (MaxChangedBlocksException e) {
  280. // TODO Auto-generated catch block
  281. e.printStackTrace();
  282. } //.paste() or .place()?
  283.  
  284. }
  285.  
  286. }
  287. public static void clear()
  288. {
  289.  
  290. if(instance != null)
  291. instance.remove();
  292.  
  293.  
  294. }
  295. private void remove() {
  296.  
  297. if(this.menu != null) {
  298. this.menu.destroy();
  299. }
  300. this.menu = null;
  301. this.named = false;
  302. this.songCount = 0;
  303. this.s = null;
  304. if(this.sp != null)
  305. this.sp.destroy();
  306. this.sp= null;
  307.  
  308. ProtectedRegion r = iceCreamMan.WGP.getRegionManager(w).getRegion("icecream");
  309. int minX = r.getMinimumPoint().getBlockX();
  310. int minY = r.getMinimumPoint().getBlockY();
  311. int minZ = r.getMinimumPoint().getBlockZ();
  312.  
  313. int maxX = r.getMaximumPoint().getBlockX();
  314. int maxY = r.getMaximumPoint().getBlockY();
  315. int maxZ = r.getMaximumPoint().getBlockZ();
  316.  
  317. int count = 0;
  318. for(int x = minX; x < maxX; x++)
  319. for(int y = minY; y < maxY; y++)
  320. for(int z = minZ; z < maxZ; z++) {
  321. Block b = w.getBlockAt(x, y, z);
  322. b.setType(Material.AIR);
  323.  
  324. count++;
  325. }
  326.  
  327. if(this.getNpc() != null) {
  328. for(Entity e:this.getNpc().getEntity().getNearbyEntities(10, 10, 10))
  329. if(e instanceof Item)
  330. e.remove();
  331.  
  332. this.getNpc().setProtected(false);
  333. this.getNpc().despawn(DespawnReason.REMOVAL);
  334. //this.getNpc().destroy();
  335.  
  336. }
  337. NPC npc = CitizensAPI.getNPCRegistry().getById(2);
  338. if(npc != null) {
  339. npc.despawn(DespawnReason.REMOVAL);
  340. if(npc != null)
  341. npc.destroy();
  342. }
  343.  
  344. System.out.println("[IceCream] Removed " + count + " Blocks. From Y: " + minY + " to " + maxY);
  345. this.spawned = false;
  346. forceSpawn = false;
  347. int minTime = plugin.getConfig().getInt("Settings.MinutesBetweenSpawnsMin");
  348. int maxTime = plugin.getConfig().getInt("Settings.MinutesBetweenSpawnsMax");
  349. int rTime = ThreadLocalRandom.current().nextInt(minTime,maxTime);
  350. this.spawnDelay = System.currentTimeMillis() + (rTime * 60 * 1000);
  351.  
  352. for(Player p:this.plugin.getServer().getOnlinePlayers())
  353. p.sendMessage(ChatColor.GREEN + "The " +ChatColor.AQUA + "Ice Cream Man " + ChatColor.GREEN + "Has moved along! Better luck next time!");
  354.  
  355. }
  356.  
  357. private Location findSafeLoc(List<Block> Ceiling) {
  358.  
  359. int maxTries = 200;
  360. Block safe = null;
  361.  
  362. for(int i = 0; i < maxTries; i ++)
  363. {
  364. int pos = ThreadLocalRandom.current().nextInt(0, this.ceil.size());
  365. Block b = this.ceil.get(pos);
  366. boolean found = false;
  367. int x = b.getX();
  368. int maxY = b.getY();
  369. int z = b.getZ();
  370.  
  371. for(int y = maxY; y > 0; y--) {
  372. for(Material mat:this.validBlocks) {
  373. if(iceCreamTimer.w.getBlockTypeIdAt(x,y,z) == mat.getId())
  374. {
  375. return iceCreamTimer.w.getBlockAt(x, y+2, z).getLocation();
  376.  
  377. }
  378. }
  379.  
  380. }
  381.  
  382. }
  383.  
  384. return null;
  385. }
  386.  
  387. private List<Block> getCeiling(World w) {
  388.  
  389.  
  390. List<Block> ceiling = new ArrayList<Block>();
  391.  
  392. RegionManager rm = iceCreamMan.WGP.getRegionManager(w);
  393.  
  394. ProtectedRegion rg = rm.getRegion("IceCream");
  395.  
  396. int minX = rg.getMinimumPoint().getBlockX();
  397. int minY = rg.getMinimumPoint().getBlockY();
  398. int minZ = rg.getMinimumPoint().getBlockZ();
  399. int maxX = rg.getMaximumPoint().getBlockX();
  400. int maxY = rg.getMaximumPoint().getBlockY();
  401. int maxZ = rg.getMaximumPoint().getBlockZ();
  402.  
  403. for(int x = minX; x < maxX; x++)
  404. for(int z = minZ;z < maxZ;z++)
  405. ceiling.add(w.getBlockAt(x, maxY, z));
  406.  
  407. return ceiling;
  408.  
  409.  
  410. }
  411.  
  412. public boolean handleClick(NPCRightClickEvent e) {
  413.  
  414. if(this.getNpc() == null || this.getNpc() != e.getNPC()) {
  415. return false;
  416. }
  417.  
  418. if(this.getNpc().getName().equalsIgnoreCase("Ice Cream Man"))
  419. {
  420.  
  421. if(this.menu == null) //first time its been opened
  422. {
  423. this.menu = new mcIconMenu("Ice Cream Man", 9, new mcIconMenu.OptionClickEventHandler() {
  424. @Override
  425. public void onOptionClick(mcIconMenu.OptionClickEvent event) {
  426. ItemStack buyItem = iceCreamTimer.instance.menu.getIcon(event.getPosition());
  427. if(buyItem == null)
  428. return;
  429.  
  430. event.setWillClose(false);
  431. //do code here to buy the item.
  432. Player p = event.getPlayer();
  433. int price = 0;
  434.  
  435. ItemMeta im = buyItem.getItemMeta();
  436.  
  437. List<String> lore = im.getLore();
  438. for(String s:lore) {
  439. if(s.startsWith(ChatColor.AQUA + "Cost:"))
  440. {
  441. String[] cost = s.split(":");
  442. price = Integer.parseInt(cost[1].trim());
  443. }
  444. }
  445.  
  446. OfflinePlayer op = plugin.getServer().getOfflinePlayer(p.getUniqueId());
  447. if(iceCreamMan.econ.getBalance(op) <= price)
  448. {
  449. p.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "(Ice Cream Man) " + ChatColor.GRAY + "You don't have " + ChatColor.RED+ "$" + ChatColor.RED + price + ChatColor.GRAY + " to buy " + ChatColor.RED + buyItem.getType().name());
  450. event.setWillClose(true);
  451. } else {
  452. //can afford
  453. p.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "(Ice Cream Man) " + ChatColor.GRAY + "Sold you " + ChatColor.GREEN+ "(1) " + ChatColor.RED + buyItem.getType().name() + ChatColor.GRAY + " for " + ChatColor.RED + "$"+ ChatColor.RED + price);
  454. iceCreamMan.econ.withdrawPlayer(op, price);
  455. //ItemStack toPlr = new ItemStack(buyItem.getType(),1);
  456. ItemStack toPlr = buyItem.clone();
  457. toPlr.setAmount(1);
  458. if(buyItem.getType() == Material.MONSTER_EGG)
  459. {
  460. org.bukkit.inventory.meta.SpawnEggMeta meta = (SpawnEggMeta) toPlr.getItemMeta();
  461. meta.setSpawnedType(EntityType.fromId(toPlr.getDurability()));
  462. meta.setDisplayName(EntityType.fromId(toPlr.getDurability()).getName());
  463. toPlr.setItemMeta(meta);
  464.  
  465. }
  466. p.getInventory().addItem(toPlr);
  467.  
  468. int newAmt = buyItem.getAmount() -1;
  469. if(newAmt <= 0)
  470. iceCreamTimer.instance.menu.removeOption(event.getPosition());
  471. else
  472. iceCreamTimer.instance.menu.updateQty(event.getPosition(), newAmt);
  473.  
  474. event.getPlayer().updateInventory();
  475.  
  476. boolean empty = true;
  477. for(int i = 0; i < 3;i++)
  478. {
  479. ItemStack is = iceCreamTimer.instance.menu.getIcon(i);
  480. if(is != null && is.getType() != Material.AIR)
  481. empty = false;
  482. }
  483.  
  484.  
  485. Inventory inv = iceCreamTimer.instance.menu.open(event.getPlayer());
  486. iceCreamTimer.instance.viewers.add(event.getPlayer());
  487. //test
  488. if(inv != null && inv.getSize() > 0)
  489. for(Player plr:iceCreamTimer.instance.viewers)
  490. {
  491. if(empty) {
  492. plr.closeInventory();
  493. plr.sendMessage("The " + ChatColor.AQUA + "Ice Cream Man" + ChatColor.RESET + " is all sold out!");
  494. iceCreamTimer.clear();
  495. } else {
  496. if(plr.getName().equalsIgnoreCase(event.getPlayer().getName()))
  497. continue;
  498. iceCreamTimer.instance.menu.open(plr);
  499. }
  500. }
  501.  
  502.  
  503.  
  504.  
  505. event.setWillClose(false);
  506. }
  507.  
  508. }
  509.  
  510.  
  511.  
  512. }, plugin);
  513.  
  514.  
  515.  
  516. for(int i = 0; i < 3; i++) {
  517.  
  518. RareItem ri = getRandomItem();
  519.  
  520.  
  521. if(ri == null)
  522. continue;
  523. for(int z = 0;z < 3; z++)
  524. if(this.menu.getIcon(z) != null)
  525. if(ri.getMat().name().equalsIgnoreCase(this.menu.getIcon(z).getType().name()))
  526. continue;
  527.  
  528. int maxAmt = 1;
  529. if(ri.getMaxAmt() > 1)
  530. maxAmt = ThreadLocalRandom.current().nextInt(1,ri.getMaxAmt());
  531.  
  532. ItemStack is3 = new ItemStack(ri.getMat(), maxAmt);
  533. if(ri.getData() != 0)
  534. is3.setDurability(ri.getData());
  535.  
  536. ItemMeta im3 = is3.getItemMeta();
  537.  
  538. im3.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
  539. int costMod = 0;
  540.  
  541. if(iceCreamMan.getEnchantables().contains(is3.getType()))
  542. {
  543. System.out.println("Found an item to enchant!");
  544. gear.randoEnchants(is3);
  545. for(int z = 0; z < 5; z++)
  546. {
  547. if(ThreadLocalRandom.current().nextInt(0,100) >= 50)
  548. gear.randoEnchants(is3);
  549. }
  550. im3.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
  551. im3.removeItemFlags(ItemFlag.HIDE_ATTRIBUTES);
  552. costMod = is3.getEnchantments().size();
  553. }
  554. //enchantables?
  555.  
  556. is3.setItemMeta(im3);
  557. String[] lore = new String[9];
  558. String end = "";
  559.  
  560. if(costMod > 0)
  561. end = ChatColor.AQUA + "Cost: " + ri.getMinPrice() * costMod;
  562. else
  563. end = ChatColor.AQUA + "Cost: " + ThreadLocalRandom.current().nextInt(ri.getMinPrice(),ri.getMaxPrice());
  564. lore = mcIconMenu.formatLore(ri.getDesc(), 30, ChatColor.AQUA, end);
  565.  
  566. //String[] lore = mcIconMenu.formatLore("Test", 30, ChatColor.AQUA);
  567. String name = is3.getType().name();
  568.  
  569. if(is3.getType() == Material.MONSTER_EGG)
  570. name = "Spawn " + EntityType.fromId(is3.getDurability());
  571.  
  572.  
  573. this.menu.setOption(i, is3, name, lore);
  574.  
  575. }
  576. }
  577.  
  578. }
  579. iceCreamTimer.instance.viewers.add(e.getClicker());
  580. if(this.menu != null)
  581. this.menu.open(e.getClicker());
  582. else {
  583. e.getClicker().sendMessage(ChatColor.AQUA + "Oh no! It appears the Ice Cream Man is all sold out!");
  584. iceCreamTimer.instance.viewers.remove(e.getClicker());
  585. }
  586.  
  587. return true;
  588.  
  589. /*
  590. if(items.length == 0)
  591. items = new ItemStack[3];
  592.  
  593.  
  594. System.out.println("Made Inventory");
  595. if(items == null || items.length == 0)
  596. System.out.println("Empty item list :");
  597. else
  598. this.inventory.setContents(items);
  599. this.inventory.openInventory(e.getClicker());
  600. System.out.println("Opened for: " + e.getClicker().getName() + " size: " + this.inventory.getContents().length );
  601.  
  602. }
  603. }
  604. */
  605.  
  606. }
  607.  
  608. private RareItem getRandomItem() {
  609.  
  610. if(RareItem.loadedItems.size() == 1) {
  611. RareItem ri = RareItem.loadedItems.get(0);
  612. return ri;
  613. }
  614.  
  615. for(int i = 0; i < RareItem.loadedItems.size(); i ++)
  616. {
  617. int selection = ThreadLocalRandom.current().nextInt(0,RareItem.loadedItems.size());
  618. RareItem ri = RareItem.loadedItems.get(selection);
  619. if(ThreadLocalRandom.current().nextDouble(0, 100) <= ri.getChance() )
  620. return ri;
  621.  
  622. }
  623. return null;
  624.  
  625. }
  626. private ItemStack getRandomItem2() {
  627.  
  628. if(RareItem.loadedItems.size() == 1) {
  629. RareItem ri = RareItem.loadedItems.get(0);
  630. int maxAmt = 1;
  631. if(ri.getMaxAmt() > 1)
  632. maxAmt = ThreadLocalRandom.current().nextInt(1,ri.getMaxAmt());
  633.  
  634. return new ItemStack(ri.getMat(),maxAmt);
  635. }
  636.  
  637. for(int i = 0; i < RareItem.loadedItems.size(); i ++)
  638. {
  639. int selection = ThreadLocalRandom.current().nextInt(0,RareItem.loadedItems.size());
  640. RareItem ri = RareItem.loadedItems.get(selection);
  641. if(ThreadLocalRandom.current().nextDouble(0, 100) <= ri.getChance() )
  642. {
  643. int maxAmt = 1;
  644. if(ri.getMaxAmt() > 1)
  645. maxAmt = ThreadLocalRandom.current().nextInt(1,ri.getMaxAmt());
  646.  
  647. return new ItemStack(ri.getMat(),maxAmt);
  648. }
  649.  
  650. }
  651. return null;
  652. }
  653.  
  654. public NPC getNpc() {
  655. return npc;
  656. }
  657.  
  658. public void setNpc(NPC npc) {
  659. this.npc = npc;
  660. }
  661.  
  662.  
  663.  
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement