Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.99 KB | None | 0 0
  1. package fr.makapush.monplugin;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.UUID;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.DyeColor;
  12. import org.bukkit.Location;
  13. import org.bukkit.Material;
  14. import org.bukkit.block.Block;
  15. import org.bukkit.entity.ArmorStand;
  16. import org.bukkit.entity.EntityType;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.event.EventHandler;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.event.block.Action;
  21. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  22. import org.bukkit.event.inventory.InventoryClickEvent;
  23. import org.bukkit.event.player.PlayerInteractAtEntityEvent;
  24. import org.bukkit.event.player.PlayerInteractEvent;
  25. import org.bukkit.event.player.PlayerToggleSneakEvent;
  26. import org.bukkit.inventory.Inventory;
  27. import org.bukkit.inventory.ItemStack;
  28. import org.bukkit.inventory.PlayerInventory;
  29. import org.bukkit.plugin.Plugin;
  30. import org.bukkit.scheduler.BukkitRunnable;
  31. import org.bukkit.util.BlockIterator;
  32. import org.bukkit.util.EulerAngle;
  33. import org.bukkit.util.Vector;
  34.  
  35. import com.connorlinfoot.actionbarapi.ActionBarAPI;
  36.  
  37. import fr.makapush.monplugin.Server.UserDataHandler;
  38.  
  39.  
  40.  
  41. public class MiniBlocks implements Listener {
  42. public static ArrayList<ArmorStand> GetArmorStands = new ArrayList<>();
  43. private Plugin plugin = MonPlugin.getPlugin(MonPlugin.class);
  44. FunctionsManager function = new FunctionsManager();
  45. Map<UUID, Boolean> CanPlace = new HashMap <> ();
  46. Map<UUID, Double> playerMult = new HashMap <> ();
  47. Map<UUID, Double> playerMultStep = new HashMap <> ();
  48. Map<UUID, String> playerRotType = new HashMap <> ();
  49. Map<UUID, Double> playerRotRoll = new HashMap <> ();
  50. Map<UUID, Double> playerRotPitch = new HashMap <> ();
  51. Map<UUID, Double> playerRotYaw = new HashMap <> ();
  52. ArrayList<Vector> BlockLocs = new ArrayList<Vector>();
  53. Map<UUID, HashMap<Vector, ItemStack>> GetPlayerCurrentSelection = new HashMap <> ();
  54.  
  55.  
  56.  
  57. @SuppressWarnings("deprecation")
  58. @EventHandler
  59. public void OnMoveCam(PlayerToggleSneakEvent e) {
  60. if (e.getPlayer().getWorld().getName().equals("ASkyBlock") || e.getPlayer().isOp()){
  61. Player p = e.getPlayer();
  62. ItemStack current = p.getInventory().getItemInMainHand();
  63. ItemStack currentLeft = p.getInventory().getItemInOffHand();
  64. int selectedSlot = p.getInventory().getHeldItemSlot();
  65. UserDataHandler user = new UserDataHandler(p.getUniqueId());
  66.  
  67. if (playerMult.get(p.getUniqueId()) == null) {
  68. playerMult.put(p.getUniqueId(), 3.00);
  69. }
  70.  
  71. if (playerRotType.get(p.getUniqueId()) == null) {
  72. playerRotType.put(p.getUniqueId(), "Pitch");
  73. playerRotPitch.put(p.getUniqueId(), 0.00);
  74. playerRotRoll.put(p.getUniqueId(), 0.00);
  75. playerRotYaw.put(p.getUniqueId(), 0.00);
  76. }
  77.  
  78. CanPlace.put(p.getUniqueId(), null);
  79. new BukkitRunnable() {
  80. @Override
  81. public void run() {
  82. if (p.isSneaking() == false) {
  83. cancel();
  84. }
  85.  
  86.  
  87.  
  88. if (p.isOnGround() == true && currentLeft.hasItemMeta() && currentLeft.getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  89.  
  90. if (playerMultStep.get(p.getUniqueId()) == null) {
  91. playerMultStep.put(p.getUniqueId(), 0.1);
  92. }
  93.  
  94. Double currentMult = playerMult.get(p.getUniqueId());
  95. Double currentStep = playerMultStep.get(p.getUniqueId());
  96. String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
  97. String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
  98. String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
  99. String modifType = user.getUserFile().getString("MiniBlock.ModifType");
  100. double roll = playerRotRoll.get(p.getUniqueId());
  101. double pitch = playerRotPitch.get(p.getUniqueId());
  102. double yaw = playerRotYaw.get(p.getUniqueId());
  103.  
  104. if (modifType.equals("Dist")) {
  105. changeDist(currentMult, selectedSlot, currentStep, p);
  106. }
  107. if (modifType.equals("Rot")) {
  108. if (playerRotType.get(p.getUniqueId()).equals("Pitch")) {
  109. if (p.getInventory().getHeldItemSlot() > selectedSlot) {
  110. playerRotPitch.put(p.getUniqueId(), pitch + 1);
  111. ActionBarAPI.sendActionBar(p, "§dPitch : §f" + pitch);
  112. p.getInventory().setHeldItemSlot(selectedSlot);
  113. }
  114. if (p.getInventory().getHeldItemSlot() < selectedSlot) {
  115. playerRotPitch.put(p.getUniqueId(), pitch - 1);
  116. ActionBarAPI.sendActionBar(p, "§dPitch : §f" + pitch);
  117. p.getInventory().setHeldItemSlot(selectedSlot);
  118. }
  119. }
  120. if (playerRotType.get(p.getUniqueId()).equals("Roll")) {
  121. if (p.getInventory().getHeldItemSlot() > selectedSlot) {
  122. playerRotRoll.put(p.getUniqueId(), roll + 1);
  123. ActionBarAPI.sendActionBar(p, "§cRoll : §f" + roll);
  124. p.getInventory().setHeldItemSlot(selectedSlot);
  125. }
  126. if (p.getInventory().getHeldItemSlot() < selectedSlot) {
  127. playerRotRoll.put(p.getUniqueId(), roll - 1);
  128. ActionBarAPI.sendActionBar(p, "§cRoll : §f" + roll);;
  129. p.getInventory().setHeldItemSlot(selectedSlot);
  130. }
  131. }
  132. if (playerRotType.get(p.getUniqueId()).equals("Yaw")) {
  133. if (p.getInventory().getHeldItemSlot() > selectedSlot) {
  134. playerRotYaw.put(p.getUniqueId(), yaw + 1);
  135. ActionBarAPI.sendActionBar(p, "§9Yaw : §f" + yaw);
  136. p.getInventory().setHeldItemSlot(selectedSlot);
  137. }
  138. if (p.getInventory().getHeldItemSlot() < selectedSlot) {
  139. playerRotYaw.put(p.getUniqueId(), yaw - 1);
  140. ActionBarAPI.sendActionBar(p, "§9Yaw : §f" + yaw);
  141. p.getInventory().setHeldItemSlot(selectedSlot);
  142. }
  143. }
  144. }
  145.  
  146. Location origin = p.getEyeLocation();
  147. Vector direction = origin.getDirection();
  148.  
  149. Block ground = getTargetBlock(p, (int) Math.round(currentMult));
  150.  
  151. direction.multiply(currentMult);
  152.  
  153. Location destination = origin.clone().add(direction);
  154. double gridSize = 2.285;
  155.  
  156. if (current.getType().isBlock()) {
  157. destination = origin.clone().add(direction.subtract(new Vector(0, 0.9, 0)));
  158. }
  159. else {
  160. destination = origin.clone().add(direction.subtract(new Vector(0, 2, 0)));
  161. }
  162.  
  163. if (alignState.equals("Désactiver")) {
  164. if (ground.getType() != Material.AIR) {
  165. int loc = ground.getY() + 1;
  166. destination.setY(loc - 0.68);
  167. }
  168. }
  169.  
  170.  
  171. calculateStandLoc(gridSize, destination, p);
  172. if (!BlockLocs.contains(destination.toVector())) {
  173. if (yawState.equals("Activer")) {
  174. destination.setYaw(0);
  175. }
  176. ArmorStand stand = (ArmorStand) p.getLocation().getWorld().spawnEntity(destination, EntityType.ARMOR_STAND);
  177.  
  178. stand.setVisible(false);
  179. if (!pitchState.equals("Activer")) {
  180. stand.setHeadPose(new EulerAngle(p.getEyeLocation().getPitch() / -55 + (pitch / 20), 109.957 + (roll / 20), yaw / 20));
  181. }
  182. else {
  183. stand.setHeadPose(new EulerAngle(pitch / 20, 109.957 + (roll / 20), yaw / 20));
  184. }
  185. stand.setHelmet(current);
  186. stand.setGravity(false);
  187. stand.setAI(false);
  188. stand.setSmall(true);
  189.  
  190.  
  191. new BukkitRunnable() {
  192. @Override
  193. public void run() {
  194. if (CanPlace.get(p.getUniqueId()) == null) {
  195. stand.remove();
  196. p.getEyeLocation().getBlock().setType(Material.AIR);
  197. }
  198. else {
  199. CanPlace.put(p.getUniqueId(), null);
  200. p.getEyeLocation().getBlock().setType(Material.AIR);
  201. BlockLocs.add(stand.getLocation().toVector());
  202. stand.setCollidable(true);
  203. p.sendMessage("§aVous avez placé un MiniBlock !");
  204. }
  205. }}.runTaskLater(plugin, 1);
  206. }}
  207. }}.runTaskTimer(plugin, 0, 2);
  208. }
  209.  
  210. }
  211.  
  212. @EventHandler
  213. public void OnTryingPlacingMiniBlocksOnEntyties(PlayerInteractAtEntityEvent e) {
  214. Player p = e.getPlayer();
  215. if (p.getInventory().getItemInOffHand().hasItemMeta()) {
  216. if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  217. if (p.isSneaking()) {
  218. CanPlace.put(p.getUniqueId(), true);
  219. e.setCancelled(true);
  220.  
  221. }
  222. }
  223. }
  224. }
  225.  
  226. @SuppressWarnings("deprecation")
  227. @EventHandler
  228. public void OnModifMiniBlock(PlayerInteractEvent e) {
  229. Player p = e.getPlayer();
  230. Action action = e.getAction();
  231. UserDataHandler user = new UserDataHandler(p.getUniqueId());
  232. String modifType = user.getUserFile().getString("MiniBlock.ModifType");
  233. if (action == Action.LEFT_CLICK_AIR && p.getInventory().getItemInOffHand().hasItemMeta()) {
  234. if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  235. if (p.isSneaking() && p.isOnGround()) {
  236. if (modifType.equals("Dist")) {
  237.  
  238. if (playerMultStep.get(p.getUniqueId()) == null) {
  239. playerMultStep.put(p.getUniqueId(), 0.1);
  240. }
  241.  
  242. if (playerMultStep.get(p.getUniqueId()) >= 1) {
  243. playerMultStep.put(p.getUniqueId(), 0.1);
  244. }
  245.  
  246. double currentStep = playerMultStep.get(p.getUniqueId());
  247. DecimalFormat df = new DecimalFormat("#.#");
  248.  
  249. ActionBarAPI.sendActionBar(p, "§cPrecision du recul : §e" + df.format(currentStep));
  250. playerMultStep.put(p.getUniqueId(), currentStep + 0.1);
  251. }
  252.  
  253.  
  254. if (playerRotType.get(p.getUniqueId()) == null) {
  255. playerRotType.put(p.getUniqueId(), "Pitch");
  256. playerRotPitch.put(p.getUniqueId(), 0.00);
  257. playerRotRoll.put(p.getUniqueId(), 0.00);
  258. playerRotYaw.put(p.getUniqueId(), 0.00);
  259. }
  260. if (modifType.equals("Rot")) {
  261. if (playerRotType.get(p.getUniqueId()).equals("Pitch")){
  262. ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §cRoll");
  263. playerRotType.put(p.getUniqueId(), "Roll");
  264. return;
  265. }
  266. if (playerRotType.get(p.getUniqueId()).equals("Roll")){
  267. playerRotType.put(p.getUniqueId(), "Yaw");
  268. ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §9Yaw");
  269. return;
  270. }
  271. if (playerRotType.get(p.getUniqueId()).equals("Yaw")){
  272. playerRotType.put(p.getUniqueId(), "Pitch");
  273. ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §dPitch");
  274. return;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281.  
  282. public void changeDist(double currentMult, int selectedSlot, double currentStep, Player p) {
  283. if (currentMult < 0.5) {
  284. currentMult = 0.5;
  285. }
  286.  
  287. if (p.getInventory().getHeldItemSlot() > selectedSlot) {
  288. playerMult.put(p.getUniqueId(),currentMult + currentStep);
  289. p.getInventory().setHeldItemSlot(selectedSlot);
  290. }
  291. if (p.getInventory().getHeldItemSlot() < selectedSlot) {
  292. playerMult.put(p.getUniqueId(),currentMult - currentStep);
  293. p.getInventory().setHeldItemSlot(selectedSlot);
  294. }
  295. }
  296.  
  297. @SuppressWarnings("deprecation")
  298. @EventHandler
  299. public void OnOpenToolConfiguration(PlayerInteractEvent e) {
  300. Player p = e.getPlayer();
  301. Action action = e.getAction();
  302. UserDataHandler user = new UserDataHandler(p.getUniqueId());
  303.  
  304. if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInMainHand().hasItemMeta()) {
  305. if (p.getInventory().getItemInMainHand().getType() != Material.HOPPER) return;
  306. if (p.getInventory().getItemInMainHand().getItemMeta().hasDisplayName() && p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  307.  
  308. Inventory inv = Bukkit.createInventory(null,45, "§9Mini Tool Configuration");
  309. function.NewPage(inv);
  310.  
  311. function.verifyNull(user, "MiniBlock.Placement.X", "Débloquer");
  312. function.verifyNull(user, "MiniBlock.Placement.Y", "Débloquer");
  313. function.verifyNull(user, "MiniBlock.Placement.Z", "Débloquer");
  314. function.verifyNull(user, "MiniBlock.Placement.face", "Bloquer");
  315. function.verifyNull(user, "MiniBlock.Rotation.pitch", "Désactiver");
  316. function.verifyNull(user, "MiniBlock.Rotation.yaw", "Désactiver");
  317. function.verifyNull(user, "MiniBlock.ModifType", "Dist");
  318. function.verifyNull(user, "MiniBlock.Placement.align", "Désactiver");
  319. String xState = user.getUserFile().getString("MiniBlock.Placement.X");
  320. String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
  321. String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
  322. String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
  323. String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
  324. String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
  325. String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
  326.  
  327. inv.setItem(36, function.getItemSpecified(Material.WOOL, DyeColor.RED.getDyeData(), "§c" + xState + " l'axe X", Arrays.asList("§7Bloquer ou débloquer l'axe X de placement du block"), false));
  328. inv.setItem(27, function.getItemSpecified(Material.WOOL, DyeColor.GREEN.getDyeData(), "§a" + yState + " l'axe Y", Arrays.asList("§7Bloquer ou débloquer l'axe Y de placement du block"), false));
  329. inv.setItem(37, function.getItemSpecified(Material.WOOL, DyeColor.BLUE.getDyeData(), "§9" + zState + " l'axe Z", Arrays.asList("§7Bloquer ou débloquer l'axe Z de placement du block"), false));
  330. inv.setItem(28, function.getItemSpecified(Material.WOOL, DyeColor.GRAY.getDyeData(), "§7" + frontState + " l'axe en face de vous", Arrays.asList("§7Bloquer ou débloquer l'axe qui figure en face de vous", "§7Pour un meilleur controle de la distance MiniBlock-Joueur", "§7Avec la molette"), false));
  331. inv.setItem(43, function.getItemSpecified(Material.WOOL, DyeColor.GREEN.getDyeData(), "§a" + pitchState + " l'axe pitch", Arrays.asList("§7Bloquer ou débloquer l'axe de rotation pitch"), false));
  332. inv.setItem(44, function.getItemSpecified(Material.WOOL, DyeColor.RED.getDyeData(), "§c" + yawState + " l'axe yaw", Arrays.asList("§7Bloquer ou débloquer l'axe de rotation yaw"), false));
  333. inv.setItem(35, function.getItemSpecified(Material.WOOL, DyeColor.BLACK.getDyeData(), "§7Réinitialiser la rotation", Arrays.asList("§7Remettre tout les axes de rotation à 0°"), false));
  334. inv.setItem(38, function.getItemSpecified(Material.WOOL, DyeColor.BLACK.getDyeData(), "§7Réinitialiser la distance Block - Joeur", Arrays.asList("§7Remettre la distance entre vous et votre MiniBlock","§7à la normale"), false));
  335. inv.setItem(18, function.getItemSpecified(Material.WOOL, DyeColor.ORANGE.getDyeData(), "§6" + alignState + " l'alignement sur le sol", Arrays.asList("§7Activer ou non l'alignement du MiniBlock sur le sol"), false));
  336. getModifItem(inv, user);
  337. p.openInventory(inv);
  338.  
  339.  
  340.  
  341. }
  342. }
  343. }
  344.  
  345. @EventHandler
  346. public void OnOpenToolConfigClick(InventoryClickEvent e) {
  347. Player p = (Player) e.getWhoClicked();
  348. ItemStack current = e.getCurrentItem();
  349. Inventory inv = e.getClickedInventory();
  350. UserDataHandler user = new UserDataHandler(p.getUniqueId());
  351.  
  352. String xState = user.getUserFile().getString("MiniBlock.Placement.X");
  353. String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
  354. String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
  355. String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
  356. String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
  357. String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
  358. String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
  359.  
  360. if (inv != null && inv.getName().equals("§9Mini Tool Configuration")) {
  361. SwitchBlockedUnblocked(inv, 36, xState, "§c", "X", current, user);
  362. SwitchBlockedUnblocked(inv, 27, yState, "§a", "Y", current, user);
  363. SwitchBlockedUnblocked(inv, 37, zState, "§9", "Z", current, user);
  364. SwitchBlockedUnblocked(inv, 28, frontState, "§7", "face", current, user);
  365. SwitchBlockedUnblockedRotation(inv, 43, pitchState, "§a", "pitch", current, user);
  366. SwitchBlockedUnblockedRotation(inv, 44, yawState, "§c", "yaw", current, user);
  367. SwitchAllowDisallowAlignement(inv, 18, alignState, "§6", "align", current, user);
  368. selectModifType(inv, user, current);
  369.  
  370.  
  371. if (current.getItemMeta().getDisplayName().equals("§7Réinitialiser la rotation")) {
  372. playerRotPitch.put(p.getUniqueId(), 0.00);
  373. playerRotRoll.put(p.getUniqueId(), 0.00);
  374. playerRotYaw.put(p.getUniqueId(), 0.00);
  375. p.sendMessage("§aLa rotation à été réinitialisée");
  376. }
  377.  
  378. if (current.getItemMeta().getDisplayName().equals("§7Réinitialiser la distance Block - Joeur")) {
  379. playerMult.put(p.getUniqueId(), 3.00);
  380. p.sendMessage("§aLa distance à été réinitialisée");
  381. }
  382. }
  383. }
  384.  
  385. public final Block getTargetBlock(Player player, int range) {
  386. BlockIterator iter = new BlockIterator(player, range);
  387. Block lastBlock = iter.next();
  388. while (iter.hasNext()) {
  389. lastBlock = iter.next();
  390. if (lastBlock.getType() == Material.AIR) {
  391. continue;
  392. }
  393. break;
  394. }
  395. return lastBlock;
  396. }
  397.  
  398. @EventHandler
  399. public void OnTryingPlacingMiniBlocksTool(PlayerInteractEvent e) {
  400. Player p = e.getPlayer();
  401. Action action = e.getAction();
  402.  
  403. if (action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInMainHand().hasItemMeta()) {
  404. if (p.getInventory().getItemInMainHand() == null) return;
  405. if (p.getInventory().getItemInMainHand().getType().equals(Material.HOPPER) && p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  406. e.setCancelled(true);
  407. }
  408. }
  409.  
  410. }
  411.  
  412. @EventHandler
  413. public void OnTryingPlacingMiniBlocks(PlayerInteractEvent e) {
  414. Player p = e.getPlayer();
  415. Action action = e.getAction();
  416. if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInOffHand().hasItemMeta()) {
  417. if (p.getInventory().getItemInMainHand() != null || p.getInventory().getItemInMainHand().getType() != Material.AIR) {
  418. if (p.getInventory().getItemInOffHand().getType().equals(Material.HOPPER)) {
  419. if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
  420. if (p.isSneaking()) {
  421. e.setCancelled(true);
  422. CanPlace.put(p.getUniqueId(), true);
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429.  
  430. @EventHandler
  431. public void OnBreakMiniBlock(EntityDamageByEntityEvent e) {
  432. if (e.getDamager() instanceof Player) {
  433. Player p = (Player) e.getDamager();
  434. if (p.getWorld().getName().equals("ASkyBlock") || p.isOp()) {
  435. if (e.getEntity() instanceof ArmorStand) {
  436. ArmorStand stand = (ArmorStand) e.getEntity();
  437. if (!stand.isVisible() && stand.isEmpty()) {
  438. stand.remove();
  439. BlockLocs.remove(stand.getLocation().toVector());
  440. e.setCancelled(true);
  441. }
  442. }
  443. }
  444.  
  445. else if (BlockLocs.contains(e.getEntity().getLocation().toVector())) {
  446. p.sendMessage("§cVous ne pouvez pas détruire ce MiniBlock !");
  447. }
  448. }
  449. }
  450.  
  451. @SuppressWarnings("deprecation")
  452. void SwitchBlockedUnblocked(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
  453. if (current.getItemMeta().getDisplayName().contains(axe)) {
  454. if (state.equals("Débloquer")) {
  455. user.getUserFile().set("MiniBlock.Placement." + axe, "Bloquer");
  456. state = user.getUserFile().getString("MiniBlock.Placement." + axe);
  457. user.saveUserFile();
  458. } else {
  459. user.getUserFile().set("MiniBlock.Placement." + axe, "Débloquer");
  460. state = user.getUserFile().getString("MiniBlock.Placement." + axe);
  461. user.saveUserFile();
  462. }
  463. if (axe.equals("face")){
  464. inv.setItem(slot, function.getItemSpecified(Material.WOOL, current.getData().getData(), color + state + " l'axe en face de vous", Arrays.asList("§7Bloquer ou débloquer l'axe qui figure en face de vous", "§7Pour un meilleur controle de la distance MiniBlock-Joueur", "§7Avec la molette"), false));
  465. return;
  466. }
  467. inv.setItem(slot, function.getItemSpecified(Material.WOOL, current.getData().getData(), color + state + " l'axe " + axe, Arrays.asList("§7Bloquer ou débloquer l'axe " + axe + " de placement du block"), false));
  468. }
  469. }
  470.  
  471. @SuppressWarnings("deprecation")
  472. void SwitchBlockedUnblockedRotation(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
  473. if (current.getItemMeta().getDisplayName().contains(axe)) {
  474. if (state.equals("Désactiver")) {
  475. user.getUserFile().set("MiniBlock.Rotation." + axe, "Activer");
  476. state = user.getUserFile().getString("MiniBlock.Rotation." + axe);
  477. user.saveUserFile();
  478. } else {
  479. user.getUserFile().set("MiniBlock.Rotation." + axe, "Désactiver");
  480. state = user.getUserFile().getString("MiniBlock.Rotation." + axe);
  481. user.saveUserFile();
  482. }
  483. inv.setItem(slot, function.getItemSpecified(Material.WOOL, current.getData().getData(), color + state + " l'axe de rotation " + axe, Arrays.asList("§7Bloquer ou débloquer l'axe de rotation" + axe), false));
  484.  
  485. }
  486. }
  487.  
  488. @SuppressWarnings("deprecation")
  489. void SwitchAllowDisallowAlignement(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
  490. if (current.getItemMeta().getDisplayName().contains(axe)) {
  491. if (state.equals("Désactiver")) {
  492. user.getUserFile().set("MiniBlock.Placement." + axe, "Activer");
  493. state = user.getUserFile().getString("MiniBlock.Placement." + axe);
  494. user.saveUserFile();
  495. } else {
  496. user.getUserFile().set("MiniBlock.Placement." + axe, "Désactiver");
  497. state = user.getUserFile().getString("MiniBlock.Placement." + axe);
  498. user.saveUserFile();
  499. }
  500. inv.setItem(slot, function.getItemSpecified(Material.WOOL, current.getData().getData(), color + state + " l'alignement sur le sol" + axe, Arrays.asList("§7Activer ou non l'alignement du MiniBlock sur le sol"), false));
  501.  
  502. }
  503. }
  504.  
  505.  
  506. @SuppressWarnings("deprecation")
  507. Inventory getModifItem(Inventory inv, UserDataHandler user) {
  508. if (user.getUserFile().getString("MiniBlock.ModifType").equals("Rot")) {
  509. inv.setItem(13, function.getItemSpecified(Material.INK_SACK, DyeColor.PINK.getDyeData() , "§aModification par molette pour rotation sélectionné", Arrays.asList("§7Modifiez la rotation du MiniBlock via la molette","§7Faites un Click Droit pour modifier le type de rotation"), false));
  510. return inv;
  511. }
  512. if (user.getUserFile().getString("MiniBlock.ModifType").equals("Dist")) {
  513. inv.setItem(13, function.getItemSpecified(Material.ARROW, (byte) 0 , "§aModification par molette pour distance sélectionné", Arrays.asList("§7Permet de modifier la distance","§7MiniBlock - Joueur via la molette / Click Droit"), false));
  514. return inv;
  515. }
  516. return inv;
  517. }
  518.  
  519. @SuppressWarnings("deprecation")
  520. Inventory selectModifType(Inventory inv, UserDataHandler user, ItemStack current) {
  521.  
  522. if (current.getType().equals(Material.ARROW)) {
  523. user.getUserFile().set("MiniBlock.ModifType", "Rot");
  524. inv.setItem(13, function.getItemSpecified(Material.INK_SACK, DyeColor.PINK.getDyeData() , "§aModification par molette pour rotation sélectionné", Arrays.asList("§7Modifiez la rotation du MiniBlock via la molette","§7Faites un Click Droit pour modifier le type de rotation"), false));
  525. user.saveUserFile();
  526. return inv;
  527. }
  528. if (current.getType().equals(Material.INK_SACK)) {
  529. user.getUserFile().set("MiniBlock.ModifType", "Select");
  530. inv.setItem(13, function.getItemSpecified(Material.ARROW, (byte) 0 , "§aModification par molette pour distance sélectionné", Arrays.asList("§7Permet de modifier la distance","§7MiniBlock - Joueur via la molette / Click Droit"), false));
  531. user.saveUserFile();
  532. return inv;
  533. }
  534. return inv;
  535. }
  536.  
  537. void swapItems(Player p,ItemStack current) {
  538. PlayerInventory inv = p.getInventory();
  539. ItemStack swappedIt = inv.getItem(4);
  540. int currentSlot = p.getInventory().getHeldItemSlot();
  541. inv.setItem(4, current);
  542. inv.setItem(currentSlot, swappedIt);
  543. }
  544.  
  545. void calculateStandLoc(double gridSize, Location destination, Player p) {
  546.  
  547. UserDataHandler user = new UserDataHandler(p.getUniqueId());
  548. function.verifyNull(user, "MiniBlock.Placement.X", "Débloquer");
  549. function.verifyNull(user, "MiniBlock.Placement.Y", "Débloquer");
  550. function.verifyNull(user, "MiniBlock.Placement.Z", "Débloquer");
  551. function.verifyNull(user, "MiniBlock.Placement.face", "Bloquer");
  552. String xState = user.getUserFile().getString("MiniBlock.Placement.X");
  553. String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
  554. String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
  555. String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
  556.  
  557.  
  558. if (yState.equals("Débloquer")) {
  559. destination.setY(FunctionsManager.roundWithCoeff(destination.getY(), gridSize));
  560. }
  561.  
  562. if (frontState.equals("Débloquer")) {
  563. if (getCardinalDirection(p) == "E" || getCardinalDirection(p) == "W") {
  564. destination.setX(FunctionsManager.roundWithCoeff(destination.getX(), gridSize));
  565. }
  566. if (getCardinalDirection(p) == "N" || getCardinalDirection(p) == "S") {
  567. destination.setZ(FunctionsManager.roundWithCoeff(destination.getZ(), gridSize));
  568. }
  569. return;
  570. }
  571.  
  572. if (zState.equals("Débloquer")) {
  573. destination.setZ(FunctionsManager.roundWithCoeff(destination.getZ(), gridSize));
  574. }
  575. if (xState.equals("Débloquer")) {
  576. destination.setX(FunctionsManager.roundWithCoeff(destination.getX(), gridSize));
  577. }
  578.  
  579. }
  580.  
  581. public static String getCardinalDirection(Player p) {
  582. double rotation = (p.getLocation().getYaw() - 90) % 360;
  583. if (rotation < 0) {
  584. rotation += 360.0;
  585. }
  586. if (0 <= rotation && rotation < 22.5) {
  587. return "N";
  588. } else if (22.5 <= rotation && rotation < 67.5) {
  589. return "NE";
  590. } else if (67.5 <= rotation && rotation < 112.5) {
  591. return "E";
  592. } else if (112.5 <= rotation && rotation < 157.5) {
  593. return "SE";
  594. } else if (157.5 <= rotation && rotation < 202.5) {
  595. return "S";
  596. } else if (202.5 <= rotation && rotation < 247.5) {
  597. return "SW";
  598. } else if (247.5 <= rotation && rotation < 292.5) {
  599. return "W";
  600. } else if (292.5 <= rotation && rotation < 337.5) {
  601. return "NW";
  602. } else if (337.5 <= rotation && rotation < 360.0) {
  603. return "N";
  604. } else {
  605. return null;
  606. }
  607. }
  608. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement