Advertisement
Lisenochek

Untitled

Oct 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. package com.realistic.signals;
  2.  
  3. import java.util.Random;
  4. import java.util.concurrent.Callable;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.BlockPlaceEvent;
  15.  
  16. import com.realistic.api.API;
  17. import com.realistic.api.MessageManager;
  18. import com.realistic.api.MessageManager.MsgType;
  19. import com.realistic.config.configMessage;
  20. import com.realistic.crate.Crate_list;
  21. import com.realistic.otherAPI.ParticleEffect;
  22.  
  23. public class Handler_Place implements Listener {
  24.  
  25. private static final Random r = new Random();
  26. public static boolean finished = false;
  27.  
  28. @EventHandler
  29. public static void onPlace(BlockPlaceEvent e) {
  30.  
  31. Player p = e.getPlayer();
  32. Block b = e.getBlockPlaced();
  33.  
  34. if (e.isCancelled()) {
  35. return;
  36. }
  37.  
  38. if (b.getType() == Material.REDSTONE_TORCH_ON) {
  39.  
  40. if (p.getItemInHand().getItemMeta().getDisplayName() != null
  41. && p.getItemInHand().getItemMeta().getDisplayName()
  42. .equalsIgnoreCase(ChatColor.GOLD + ChatColor.BOLD.toString() + "Сигнальная шашка")) {
  43.  
  44. MessageManager.getManager().msg(p, MsgType.SUCCESS,
  45. configMessage.messageConfig.getString("signal_enable"));
  46.  
  47. spawn(b.getLocation(), b, p);
  48. }
  49. }
  50. }
  51.  
  52. public static void spawn(Location loc, Block b, Player p) {
  53.  
  54. finished = true;
  55.  
  56. new Thread() {
  57.  
  58. @SuppressWarnings("deprecation")
  59. @Override
  60. public void run() {
  61.  
  62. while (true) {
  63.  
  64. try {
  65. Thread.sleep(200);
  66. } catch (InterruptedException e) {
  67. return;
  68. }
  69.  
  70. if (finished) {
  71. p.sendMessage("выкл");
  72. finished = false;
  73. this.interrupt();
  74. this.stop();
  75. }
  76.  
  77. if (loc.getBlock().getType() != Material.AIR) {
  78. p.sendMessage("1");
  79. continue;
  80. }
  81.  
  82. ParticleEffect.SMOKE_LARGE.display(0, 2, 0, 0, 5, b.getLocation().add(0.5, 3, 0.5), 200);
  83.  
  84. if (r.nextInt(5000) <= 100) {
  85.  
  86. Bukkit.getScheduler().callSyncMethod(API.getInstance(), new Callable<Crate_list>() {
  87.  
  88. @Override
  89. public Crate_list call() throws Exception {
  90.  
  91. p.sendMessage("2");
  92. b.setType(Material.AIR);
  93. Crate_list.commonCrate(loc, b, p);
  94. return null;
  95. }
  96. });
  97. }
  98. }
  99. }
  100. }.start();
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement