Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package pl.arivi.sectors.utils;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.World;
  5. import pl.arivi.sectors.data.Sector;
  6. import pl.arivi.sectors.managers.SectorManager;
  7.  
  8. public class KncokUtil
  9. {
  10. public static Location correctedPosition(Location loc, int knock)
  11. {
  12. double xLoc = loc.getX();
  13. double zLoc = loc.getZ();
  14. double yLoc = loc.getY();
  15.  
  16. Sector sector = SectorManager.getSector();
  17. int minX = sector.getMinX();
  18. int maxX = sector.getMaxX();
  19. int minZ = sector.getMinZ();
  20. int maxZ = sector.getMaxZ();
  21.  
  22. if (xLoc <= minX)
  23. xLoc = minX + knock;
  24. else if (xLoc >= maxX) {
  25. xLoc = maxX - knock;
  26. }
  27. if (zLoc <= minZ)
  28. zLoc = minZ + knock;
  29. else if (zLoc >= maxZ) {
  30. zLoc = maxZ - knock;
  31. }
  32. double y = loc.getWorld().getHighestBlockYAt((int)xLoc, (int)zLoc) + 1.5F;
  33.  
  34. return new Location(loc.getWorld(), Math.floor(xLoc) + 0.5D, y, Math.floor(zLoc) + 0.5D, loc.getYaw(), loc.getPitch());
  35. }
  36.  
  37. public static Location pvp(Location loc, int knock)
  38. {
  39. double xLoc = loc.getX();
  40. double zLoc = loc.getZ();
  41. double yLoc = loc.getY();
  42.  
  43. Sector sector = SectorManager.getSector();
  44. int minX = sector.getMinX();
  45. int maxX = sector.getMaxX();
  46. int minZ = sector.getMinZ();
  47. int maxZ = sector.getMaxZ();
  48.  
  49. if (xLoc - 12.0D <= minX)
  50. xLoc = minX + knock;
  51. else if (xLoc + 12.0D >= maxX) {
  52. xLoc = maxX - knock;
  53. }
  54. if (zLoc - 12.0D <= minZ)
  55. zLoc = minZ + knock;
  56. else if (zLoc + 12.0D >= maxZ) {
  57. zLoc = maxZ - knock;
  58. }
  59. double y = loc.getWorld().getHighestBlockYAt((int)xLoc, (int)zLoc) + 1.5F;
  60.  
  61. return new Location(loc.getWorld(), Math.floor(xLoc) + 0.5D, y, Math.floor(zLoc) + 0.5D, loc.getYaw(), loc.getPitch());
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement