Advertisement
Guest User

CameraStudio null

a guest
Jul 12th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. public class CameraStudio extends JavaPlugin implements Listener {
  2. public static CameraStudio instance;
  3. static String prefix = ChatColor.AQUA + "[" + ChatColor.DARK_AQUA + "CP" + ChatColor.AQUA + "CameraStudio] "
  4. + ChatColor.GREEN;
  5. public static HashSet<UUID> travelling = new HashSet<UUID>();
  6. public static HashSet<UUID> stopping = new HashSet<UUID>();
  7.  
  8.  
  9.  
  10. public void onDisable() {
  11. getLogger().info("CameraStudio disabled");
  12. }
  13.  
  14. public void onEnable() {
  15.  
  16. instance = this;
  17.  
  18. getServer().getPluginManager().registerEvents(this, this);
  19. this.getCommand("cam").setExecutor(new CamCommand());
  20. getConfig().options().copyDefaults(true);
  21. saveConfig();
  22. getLogger().info(prefix + "CPCameraStudioReborn has been enabled!");
  23. }
  24.  
  25. public static double round(double unrounded, int precision) {
  26. BigDecimal bd = new BigDecimal(unrounded);
  27. BigDecimal rounded = bd.setScale(precision, 4);
  28. return rounded.doubleValue();
  29. }
  30.  
  31. @EventHandler
  32. public void onPlayerJoined(final PlayerJoinEvent event) {
  33. if (getConfig().getBoolean("show-join-message")) {
  34. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  35. public void run() {
  36. event.getPlayer()
  37. .sendMessage(prefix + "This server is running the Camera Studio Plugin v"
  38. + instance.getDescription().getVersion() + " by " + ChatColor.AQUA
  39. + "CrushedPixel. Updated by chrismin13.");
  40. event.getPlayer().sendMessage(prefix + ChatColor.YELLOW + "http://youtube.com/CrushedPixel");
  41. }
  42. }, 10L);
  43. }
  44. }
  45.  
  46. @EventHandler
  47. public void onPlayerLeave(final PlayerQuitEvent event) {
  48. if (getConfig().getBoolean("clear-points-on-disconnect")
  49. && CamCommand.points.get(event.getPlayer().getUniqueId()) != null)
  50. CamCommand.points.get(event.getPlayer().getUniqueId()).clear();
  51. }
  52.  
  53. public static void travel(final Player player, List<Location> locations, int time, String FailMessage,
  54. final String CompletedMessage) {
  55. List<Double> diffs = new ArrayList<Double>();
  56. List<Integer> travelTimes = new ArrayList<Integer>();
  57.  
  58. double totalDiff = 0.0D;
  59.  
  60. for (int i = 0; i < locations.size() - 1; i++) {
  61. Location s = (Location) locations.get(i);
  62. Location n = (Location) locations.get(i + 1);
  63. double diff = CameraStudio.positionDifference(s, n);
  64. totalDiff += diff;
  65. diffs.add(Double.valueOf(diff));
  66. }
  67.  
  68. for (Iterator<Double> n = diffs.iterator(); n.hasNext();) {
  69. double d = ((Double) n.next()).doubleValue();
  70. travelTimes.add(Integer.valueOf((int) (d / totalDiff * time)));
  71. }
  72.  
  73. final List<Location> tps = new ArrayList<Location>();
  74.  
  75. World w = player.getWorld();
  76.  
  77. for (int i = 0; i < locations.size() - 1; i++) {
  78. Location s = (Location) locations.get(i);
  79. Location n = (Location) locations.get(i + 1);
  80. int t = ((Integer) travelTimes.get(i)).intValue();
  81.  
  82. double moveX = n.getX() - s.getX();
  83. double moveY = n.getY() - s.getY();
  84. double moveZ = n.getZ() - s.getZ();
  85. double movePitch = n.getPitch() - s.getPitch();
  86.  
  87. double yawDiff = Math.abs(n.getYaw() - s.getYaw());
  88. double c = 0.0D;
  89.  
  90. if (yawDiff <= 180.0D) {
  91. if (s.getYaw() < n.getYaw()) {
  92. c = yawDiff;
  93. } else {
  94. c = -yawDiff;
  95. }
  96. } else if (s.getYaw() < n.getYaw()) {
  97. c = -(360.0D - yawDiff);
  98. } else {
  99. c = 360.0D - yawDiff;
  100. }
  101.  
  102. double d = c / t;
  103.  
  104. for (int x = 0; x < t; x++) {
  105. Location l = new Location(w, s.getX() + moveX / t * x, s.getY() + moveY / t * x,
  106. s.getZ() + moveZ / t * x, (float) (s.getYaw() + d * x),
  107. (float) (s.getPitch() + movePitch / t * x));
  108. tps.add(l);
  109. }
  110.  
  111. }
  112.  
  113. //try {
  114. player.setAllowFlight(true);
  115. player.setFlying(true);
  116. travelling.add(player.getUniqueId());
  117. //Fixed by Ultrajungleboy to make sure that the players chunks are loading when in cutscene
  118. //Was using Deprecated bukkittask before
  119. BukkitTask travelTask = new TravelTask(tps, player, CompletedMessage).runTaskTimer(instance, 0L, 1L);
  120. //}
  121. //catch (Exception e) {
  122. //if (FailMessage != null)
  123. //player.sendMessage(FailMessage);
  124. //}
  125. }
  126.  
  127. public static int parseTimeString(String timeString) throws java.text.ParseException {
  128. Date length;
  129. try {
  130. SimpleDateFormat formatter = new SimpleDateFormat("mm'm'ss's'");
  131. length = formatter.parse(timeString);
  132. } catch (Exception e) {
  133. try {
  134. SimpleDateFormat formatter = new SimpleDateFormat("m'm'ss's'");
  135. length = formatter.parse(timeString);
  136. } catch (Exception e1) {
  137. try {
  138. SimpleDateFormat formatter = new SimpleDateFormat("m'm's's'");
  139. length = formatter.parse(timeString);
  140. } catch (Exception e2) {
  141. try {
  142. SimpleDateFormat formatter = new SimpleDateFormat("mm'm's's'");
  143. length = formatter.parse(timeString);
  144. } catch (Exception e3) {
  145. try {
  146. SimpleDateFormat formatter = new SimpleDateFormat("mm'm'");
  147. length = formatter.parse(timeString);
  148. } catch (Exception e4) {
  149. try {
  150. SimpleDateFormat formatter = new SimpleDateFormat("m'm'");
  151. length = formatter.parse(timeString);
  152. } catch (Exception e5) {
  153. try {
  154. SimpleDateFormat formatter = new SimpleDateFormat("s's'");
  155. length = formatter.parse(timeString);
  156. } catch (Exception e6) {
  157. SimpleDateFormat formatter = new SimpleDateFormat("ss's'");
  158. length = formatter.parse(timeString);
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166.  
  167. Calendar cal = GregorianCalendar.getInstance();
  168. cal.setTime(length);
  169.  
  170. int time = (cal.get(12) * 60 + cal.get(13)) * 20;
  171.  
  172. return time;
  173. }
  174.  
  175. public static double positionDifference(Location cLoc, Location eLoc) {
  176. double cX = cLoc.getX();
  177. double cY = cLoc.getY();
  178. double cZ = cLoc.getZ();
  179.  
  180. double eX = eLoc.getX();
  181. double eY = eLoc.getY();
  182. double eZ = eLoc.getZ();
  183.  
  184. double dX = eX - cX;
  185. if (dX < 0.0D) {
  186. dX = -dX;
  187. }
  188. double dZ = eZ - cZ;
  189. if (dZ < 0.0D) {
  190. dZ = -dZ;
  191. }
  192. double dXZ = Math.hypot(dX, dZ);
  193.  
  194. double dY = eY - cY;
  195. if (dY < 0.0D) {
  196. dY = -dY;
  197. }
  198. double dXYZ = Math.hypot(dXZ, dY);
  199.  
  200. return dXYZ;
  201. }
  202.  
  203. public static boolean isTravelling(UUID PlayerUUID) {
  204. if (travelling.contains(PlayerUUID))
  205. return true;
  206. return false;
  207. }
  208.  
  209. public static void stop(final UUID playerUUID) {
  210. stopping.add(playerUUID);
  211. }
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement