Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.makapush.monplugin;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.DyeColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerInteractAtEntityEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerToggleSneakEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.BlockIterator;
- import org.bukkit.util.EulerAngle;
- import org.bukkit.util.Vector;
- import com.connorlinfoot.actionbarapi.ActionBarAPI;
- import fr.makapush.monplugin.Server.UserDataHandler;
- public class MiniBlocks implements Listener {
- public static ArrayList<ArmorStand> GetArmorStands = new ArrayList<>();
- private Plugin plugin = MonPlugin.getPlugin(MonPlugin.class);
- FunctionsManager function = new FunctionsManager();
- Map<UUID, Boolean> CanPlace = new HashMap <> ();
- Map<UUID, Double> playerMult = new HashMap <> ();
- Map<UUID, Double> playerMultStep = new HashMap <> ();
- Map<UUID, String> playerRotType = new HashMap <> ();
- Map<UUID, Double> playerRotRoll = new HashMap <> ();
- Map<UUID, Double> playerRotPitch = new HashMap <> ();
- Map<UUID, Double> playerRotYaw = new HashMap <> ();
- ArrayList<Vector> BlockLocs = new ArrayList<Vector>();
- Map<UUID, HashMap<Vector, ItemStack>> GetPlayerCurrentSelection = new HashMap <> ();
- @SuppressWarnings("deprecation")
- @EventHandler
- public void OnMoveCam(PlayerToggleSneakEvent e) {
- if (e.getPlayer().getWorld().getName().equals("ASkyBlock") || e.getPlayer().isOp()){
- Player p = e.getPlayer();
- ItemStack current = p.getInventory().getItemInMainHand();
- ItemStack currentLeft = p.getInventory().getItemInOffHand();
- int selectedSlot = p.getInventory().getHeldItemSlot();
- UserDataHandler user = new UserDataHandler(p.getUniqueId());
- if (playerMult.get(p.getUniqueId()) == null) {
- playerMult.put(p.getUniqueId(), 3.00);
- }
- if (playerRotType.get(p.getUniqueId()) == null) {
- playerRotType.put(p.getUniqueId(), "Pitch");
- playerRotPitch.put(p.getUniqueId(), 0.00);
- playerRotRoll.put(p.getUniqueId(), 0.00);
- playerRotYaw.put(p.getUniqueId(), 0.00);
- }
- CanPlace.put(p.getUniqueId(), null);
- new BukkitRunnable() {
- @Override
- public void run() {
- if (p.isSneaking() == false) {
- cancel();
- }
- if (p.isOnGround() == true && currentLeft.hasItemMeta() && currentLeft.getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- if (playerMultStep.get(p.getUniqueId()) == null) {
- playerMultStep.put(p.getUniqueId(), 0.1);
- }
- Double currentMult = playerMult.get(p.getUniqueId());
- Double currentStep = playerMultStep.get(p.getUniqueId());
- String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
- String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
- String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
- String modifType = user.getUserFile().getString("MiniBlock.ModifType");
- double roll = playerRotRoll.get(p.getUniqueId());
- double pitch = playerRotPitch.get(p.getUniqueId());
- double yaw = playerRotYaw.get(p.getUniqueId());
- if (modifType.equals("Dist")) {
- changeDist(currentMult, selectedSlot, currentStep, p);
- }
- if (modifType.equals("Rot")) {
- if (playerRotType.get(p.getUniqueId()).equals("Pitch")) {
- if (p.getInventory().getHeldItemSlot() > selectedSlot) {
- playerRotPitch.put(p.getUniqueId(), pitch + 1);
- ActionBarAPI.sendActionBar(p, "§dPitch : §f" + pitch);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- if (p.getInventory().getHeldItemSlot() < selectedSlot) {
- playerRotPitch.put(p.getUniqueId(), pitch - 1);
- ActionBarAPI.sendActionBar(p, "§dPitch : §f" + pitch);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- }
- if (playerRotType.get(p.getUniqueId()).equals("Roll")) {
- if (p.getInventory().getHeldItemSlot() > selectedSlot) {
- playerRotRoll.put(p.getUniqueId(), roll + 1);
- ActionBarAPI.sendActionBar(p, "§cRoll : §f" + roll);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- if (p.getInventory().getHeldItemSlot() < selectedSlot) {
- playerRotRoll.put(p.getUniqueId(), roll - 1);
- ActionBarAPI.sendActionBar(p, "§cRoll : §f" + roll);;
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- }
- if (playerRotType.get(p.getUniqueId()).equals("Yaw")) {
- if (p.getInventory().getHeldItemSlot() > selectedSlot) {
- playerRotYaw.put(p.getUniqueId(), yaw + 1);
- ActionBarAPI.sendActionBar(p, "§9Yaw : §f" + yaw);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- if (p.getInventory().getHeldItemSlot() < selectedSlot) {
- playerRotYaw.put(p.getUniqueId(), yaw - 1);
- ActionBarAPI.sendActionBar(p, "§9Yaw : §f" + yaw);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- }
- }
- Location origin = p.getEyeLocation();
- Vector direction = origin.getDirection();
- Block ground = getTargetBlock(p, (int) Math.round(currentMult));
- direction.multiply(currentMult);
- Location destination = origin.clone().add(direction);
- double gridSize = 2.285;
- if (current.getType().isBlock()) {
- destination = origin.clone().add(direction.subtract(new Vector(0, 0.9, 0)));
- }
- else {
- destination = origin.clone().add(direction.subtract(new Vector(0, 2, 0)));
- }
- if (alignState.equals("Désactiver")) {
- if (ground.getType() != Material.AIR) {
- int loc = ground.getY() + 1;
- destination.setY(loc - 0.68);
- }
- }
- calculateStandLoc(gridSize, destination, p);
- if (!BlockLocs.contains(destination.toVector())) {
- if (yawState.equals("Activer")) {
- destination.setYaw(0);
- }
- ArmorStand stand = (ArmorStand) p.getLocation().getWorld().spawnEntity(destination, EntityType.ARMOR_STAND);
- stand.setVisible(false);
- if (!pitchState.equals("Activer")) {
- stand.setHeadPose(new EulerAngle(p.getEyeLocation().getPitch() / -55 + (pitch / 20), 109.957 + (roll / 20), yaw / 20));
- }
- else {
- stand.setHeadPose(new EulerAngle(pitch / 20, 109.957 + (roll / 20), yaw / 20));
- }
- stand.setHelmet(current);
- stand.setGravity(false);
- stand.setAI(false);
- stand.setSmall(true);
- new BukkitRunnable() {
- @Override
- public void run() {
- if (CanPlace.get(p.getUniqueId()) == null) {
- stand.remove();
- p.getEyeLocation().getBlock().setType(Material.AIR);
- }
- else {
- CanPlace.put(p.getUniqueId(), null);
- p.getEyeLocation().getBlock().setType(Material.AIR);
- BlockLocs.add(stand.getLocation().toVector());
- stand.setCollidable(true);
- p.sendMessage("§aVous avez placé un MiniBlock !");
- }
- }}.runTaskLater(plugin, 1);
- }}
- }}.runTaskTimer(plugin, 0, 2);
- }
- }
- @EventHandler
- public void OnTryingPlacingMiniBlocksOnEntyties(PlayerInteractAtEntityEvent e) {
- Player p = e.getPlayer();
- if (p.getInventory().getItemInOffHand().hasItemMeta()) {
- if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- if (p.isSneaking()) {
- CanPlace.put(p.getUniqueId(), true);
- e.setCancelled(true);
- }
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void OnModifMiniBlock(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Action action = e.getAction();
- UserDataHandler user = new UserDataHandler(p.getUniqueId());
- String modifType = user.getUserFile().getString("MiniBlock.ModifType");
- if (action == Action.LEFT_CLICK_AIR && p.getInventory().getItemInOffHand().hasItemMeta()) {
- if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- if (p.isSneaking() && p.isOnGround()) {
- if (modifType.equals("Dist")) {
- if (playerMultStep.get(p.getUniqueId()) == null) {
- playerMultStep.put(p.getUniqueId(), 0.1);
- }
- if (playerMultStep.get(p.getUniqueId()) >= 1) {
- playerMultStep.put(p.getUniqueId(), 0.1);
- }
- double currentStep = playerMultStep.get(p.getUniqueId());
- DecimalFormat df = new DecimalFormat("#.#");
- ActionBarAPI.sendActionBar(p, "§cPrecision du recul : §e" + df.format(currentStep));
- playerMultStep.put(p.getUniqueId(), currentStep + 0.1);
- }
- if (playerRotType.get(p.getUniqueId()) == null) {
- playerRotType.put(p.getUniqueId(), "Pitch");
- playerRotPitch.put(p.getUniqueId(), 0.00);
- playerRotRoll.put(p.getUniqueId(), 0.00);
- playerRotYaw.put(p.getUniqueId(), 0.00);
- }
- if (modifType.equals("Rot")) {
- if (playerRotType.get(p.getUniqueId()).equals("Pitch")){
- ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §cRoll");
- playerRotType.put(p.getUniqueId(), "Roll");
- return;
- }
- if (playerRotType.get(p.getUniqueId()).equals("Roll")){
- playerRotType.put(p.getUniqueId(), "Yaw");
- ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §9Yaw");
- return;
- }
- if (playerRotType.get(p.getUniqueId()).equals("Yaw")){
- playerRotType.put(p.getUniqueId(), "Pitch");
- ActionBarAPI.sendActionBar(p, "§eVous avez sélectionné l'axe : §dPitch");
- return;
- }
- }
- }
- }
- }
- }
- public void changeDist(double currentMult, int selectedSlot, double currentStep, Player p) {
- if (currentMult < 0.5) {
- currentMult = 0.5;
- }
- if (p.getInventory().getHeldItemSlot() > selectedSlot) {
- playerMult.put(p.getUniqueId(),currentMult + currentStep);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- if (p.getInventory().getHeldItemSlot() < selectedSlot) {
- playerMult.put(p.getUniqueId(),currentMult - currentStep);
- p.getInventory().setHeldItemSlot(selectedSlot);
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void OnOpenToolConfiguration(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Action action = e.getAction();
- UserDataHandler user = new UserDataHandler(p.getUniqueId());
- if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInMainHand().hasItemMeta()) {
- if (p.getInventory().getItemInMainHand().getType() != Material.HOPPER) return;
- if (p.getInventory().getItemInMainHand().getItemMeta().hasDisplayName() && p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- Inventory inv = Bukkit.createInventory(null,45, "§9Mini Tool Configuration");
- function.NewPage(inv);
- function.verifyNull(user, "MiniBlock.Placement.X", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.Y", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.Z", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.face", "Bloquer");
- function.verifyNull(user, "MiniBlock.Rotation.pitch", "Désactiver");
- function.verifyNull(user, "MiniBlock.Rotation.yaw", "Désactiver");
- function.verifyNull(user, "MiniBlock.ModifType", "Dist");
- function.verifyNull(user, "MiniBlock.Placement.align", "Désactiver");
- String xState = user.getUserFile().getString("MiniBlock.Placement.X");
- String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
- String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
- String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
- String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
- String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
- String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
- 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));
- 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));
- 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));
- 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));
- 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));
- 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));
- inv.setItem(35, function.getItemSpecified(Material.WOOL, DyeColor.BLACK.getDyeData(), "§7Réinitialiser la rotation", Arrays.asList("§7Remettre tout les axes de rotation à 0°"), false));
- 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));
- 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));
- getModifItem(inv, user);
- p.openInventory(inv);
- }
- }
- }
- @EventHandler
- public void OnOpenToolConfigClick(InventoryClickEvent e) {
- Player p = (Player) e.getWhoClicked();
- ItemStack current = e.getCurrentItem();
- Inventory inv = e.getClickedInventory();
- UserDataHandler user = new UserDataHandler(p.getUniqueId());
- String xState = user.getUserFile().getString("MiniBlock.Placement.X");
- String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
- String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
- String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
- String pitchState = user.getUserFile().getString("MiniBlock.Rotation.pitch");
- String yawState = user.getUserFile().getString("MiniBlock.Rotation.yaw");
- String alignState = user.getUserFile().getString("MiniBlock.Placement.align");
- if (inv != null && inv.getName().equals("§9Mini Tool Configuration")) {
- SwitchBlockedUnblocked(inv, 36, xState, "§c", "X", current, user);
- SwitchBlockedUnblocked(inv, 27, yState, "§a", "Y", current, user);
- SwitchBlockedUnblocked(inv, 37, zState, "§9", "Z", current, user);
- SwitchBlockedUnblocked(inv, 28, frontState, "§7", "face", current, user);
- SwitchBlockedUnblockedRotation(inv, 43, pitchState, "§a", "pitch", current, user);
- SwitchBlockedUnblockedRotation(inv, 44, yawState, "§c", "yaw", current, user);
- SwitchAllowDisallowAlignement(inv, 18, alignState, "§6", "align", current, user);
- selectModifType(inv, user, current);
- if (current.getItemMeta().getDisplayName().equals("§7Réinitialiser la rotation")) {
- playerRotPitch.put(p.getUniqueId(), 0.00);
- playerRotRoll.put(p.getUniqueId(), 0.00);
- playerRotYaw.put(p.getUniqueId(), 0.00);
- p.sendMessage("§aLa rotation à été réinitialisée");
- }
- if (current.getItemMeta().getDisplayName().equals("§7Réinitialiser la distance Block - Joeur")) {
- playerMult.put(p.getUniqueId(), 3.00);
- p.sendMessage("§aLa distance à été réinitialisée");
- }
- }
- }
- public final Block getTargetBlock(Player player, int range) {
- BlockIterator iter = new BlockIterator(player, range);
- Block lastBlock = iter.next();
- while (iter.hasNext()) {
- lastBlock = iter.next();
- if (lastBlock.getType() == Material.AIR) {
- continue;
- }
- break;
- }
- return lastBlock;
- }
- @EventHandler
- public void OnTryingPlacingMiniBlocksTool(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Action action = e.getAction();
- if (action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInMainHand().hasItemMeta()) {
- if (p.getInventory().getItemInMainHand() == null) return;
- if (p.getInventory().getItemInMainHand().getType().equals(Material.HOPPER) && p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- e.setCancelled(true);
- }
- }
- }
- @EventHandler
- public void OnTryingPlacingMiniBlocks(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Action action = e.getAction();
- if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInOffHand().hasItemMeta()) {
- if (p.getInventory().getItemInMainHand() != null || p.getInventory().getItemInMainHand().getType() != Material.AIR) {
- if (p.getInventory().getItemInOffHand().getType().equals(Material.HOPPER)) {
- if (p.getInventory().getItemInOffHand().getItemMeta().getDisplayName().equals("§9Mini Block Tool")) {
- if (p.isSneaking()) {
- e.setCancelled(true);
- CanPlace.put(p.getUniqueId(), true);
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void OnBreakMiniBlock(EntityDamageByEntityEvent e) {
- if (e.getDamager() instanceof Player) {
- Player p = (Player) e.getDamager();
- if (p.getWorld().getName().equals("ASkyBlock") || p.isOp()) {
- if (e.getEntity() instanceof ArmorStand) {
- ArmorStand stand = (ArmorStand) e.getEntity();
- if (!stand.isVisible() && stand.isEmpty()) {
- stand.remove();
- BlockLocs.remove(stand.getLocation().toVector());
- e.setCancelled(true);
- }
- }
- }
- else if (BlockLocs.contains(e.getEntity().getLocation().toVector())) {
- p.sendMessage("§cVous ne pouvez pas détruire ce MiniBlock !");
- }
- }
- }
- @SuppressWarnings("deprecation")
- void SwitchBlockedUnblocked(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
- if (current.getItemMeta().getDisplayName().contains(axe)) {
- if (state.equals("Débloquer")) {
- user.getUserFile().set("MiniBlock.Placement." + axe, "Bloquer");
- state = user.getUserFile().getString("MiniBlock.Placement." + axe);
- user.saveUserFile();
- } else {
- user.getUserFile().set("MiniBlock.Placement." + axe, "Débloquer");
- state = user.getUserFile().getString("MiniBlock.Placement." + axe);
- user.saveUserFile();
- }
- if (axe.equals("face")){
- 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));
- return;
- }
- 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));
- }
- }
- @SuppressWarnings("deprecation")
- void SwitchBlockedUnblockedRotation(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
- if (current.getItemMeta().getDisplayName().contains(axe)) {
- if (state.equals("Désactiver")) {
- user.getUserFile().set("MiniBlock.Rotation." + axe, "Activer");
- state = user.getUserFile().getString("MiniBlock.Rotation." + axe);
- user.saveUserFile();
- } else {
- user.getUserFile().set("MiniBlock.Rotation." + axe, "Désactiver");
- state = user.getUserFile().getString("MiniBlock.Rotation." + axe);
- user.saveUserFile();
- }
- 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));
- }
- }
- @SuppressWarnings("deprecation")
- void SwitchAllowDisallowAlignement(Inventory inv, int slot, String state, String color, String axe, ItemStack current, UserDataHandler user) {
- if (current.getItemMeta().getDisplayName().contains(axe)) {
- if (state.equals("Désactiver")) {
- user.getUserFile().set("MiniBlock.Placement." + axe, "Activer");
- state = user.getUserFile().getString("MiniBlock.Placement." + axe);
- user.saveUserFile();
- } else {
- user.getUserFile().set("MiniBlock.Placement." + axe, "Désactiver");
- state = user.getUserFile().getString("MiniBlock.Placement." + axe);
- user.saveUserFile();
- }
- 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));
- }
- }
- @SuppressWarnings("deprecation")
- Inventory getModifItem(Inventory inv, UserDataHandler user) {
- if (user.getUserFile().getString("MiniBlock.ModifType").equals("Rot")) {
- 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));
- return inv;
- }
- if (user.getUserFile().getString("MiniBlock.ModifType").equals("Dist")) {
- 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));
- return inv;
- }
- return inv;
- }
- @SuppressWarnings("deprecation")
- Inventory selectModifType(Inventory inv, UserDataHandler user, ItemStack current) {
- if (current.getType().equals(Material.ARROW)) {
- user.getUserFile().set("MiniBlock.ModifType", "Rot");
- 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));
- user.saveUserFile();
- return inv;
- }
- if (current.getType().equals(Material.INK_SACK)) {
- user.getUserFile().set("MiniBlock.ModifType", "Select");
- 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));
- user.saveUserFile();
- return inv;
- }
- return inv;
- }
- void swapItems(Player p,ItemStack current) {
- PlayerInventory inv = p.getInventory();
- ItemStack swappedIt = inv.getItem(4);
- int currentSlot = p.getInventory().getHeldItemSlot();
- inv.setItem(4, current);
- inv.setItem(currentSlot, swappedIt);
- }
- void calculateStandLoc(double gridSize, Location destination, Player p) {
- UserDataHandler user = new UserDataHandler(p.getUniqueId());
- function.verifyNull(user, "MiniBlock.Placement.X", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.Y", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.Z", "Débloquer");
- function.verifyNull(user, "MiniBlock.Placement.face", "Bloquer");
- String xState = user.getUserFile().getString("MiniBlock.Placement.X");
- String yState = user.getUserFile().getString("MiniBlock.Placement.Y");
- String zState = user.getUserFile().getString("MiniBlock.Placement.Z");
- String frontState = user.getUserFile().getString("MiniBlock.Placement.face");
- if (yState.equals("Débloquer")) {
- destination.setY(FunctionsManager.roundWithCoeff(destination.getY(), gridSize));
- }
- if (frontState.equals("Débloquer")) {
- if (getCardinalDirection(p) == "E" || getCardinalDirection(p) == "W") {
- destination.setX(FunctionsManager.roundWithCoeff(destination.getX(), gridSize));
- }
- if (getCardinalDirection(p) == "N" || getCardinalDirection(p) == "S") {
- destination.setZ(FunctionsManager.roundWithCoeff(destination.getZ(), gridSize));
- }
- return;
- }
- if (zState.equals("Débloquer")) {
- destination.setZ(FunctionsManager.roundWithCoeff(destination.getZ(), gridSize));
- }
- if (xState.equals("Débloquer")) {
- destination.setX(FunctionsManager.roundWithCoeff(destination.getX(), gridSize));
- }
- }
- public static String getCardinalDirection(Player p) {
- double rotation = (p.getLocation().getYaw() - 90) % 360;
- if (rotation < 0) {
- rotation += 360.0;
- }
- if (0 <= rotation && rotation < 22.5) {
- return "N";
- } else if (22.5 <= rotation && rotation < 67.5) {
- return "NE";
- } else if (67.5 <= rotation && rotation < 112.5) {
- return "E";
- } else if (112.5 <= rotation && rotation < 157.5) {
- return "SE";
- } else if (157.5 <= rotation && rotation < 202.5) {
- return "S";
- } else if (202.5 <= rotation && rotation < 247.5) {
- return "SW";
- } else if (247.5 <= rotation && rotation < 292.5) {
- return "W";
- } else if (292.5 <= rotation && rotation < 337.5) {
- return "NW";
- } else if (337.5 <= rotation && rotation < 360.0) {
- return "N";
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement