11package nl .svenar .powercamera ;
22
33import java .util .ArrayList ;
4+ import java .util .HashMap ;
45import java .util .List ;
56
7+ import org .bukkit .Bukkit ;
68import org .bukkit .ChatColor ;
79import org .bukkit .GameMode ;
810import org .bukkit .Location ;
@@ -23,6 +25,7 @@ public class CameraHandler extends BukkitRunnable {
2325 private String camera_name ;
2426
2527 private ArrayList <Location > camera_path_points = new ArrayList <Location >();
28+ private HashMap <Integer , ArrayList <String >> camera_path_commands = new HashMap <Integer , ArrayList <String >>();
2629
2730 private GameMode previous_gamemode ;
2831 private Location previous_player_location ;
@@ -38,23 +41,55 @@ public CameraHandler generatePath() {
3841 int max_points = (this .plugin .getConfigCameras ().getDuration (this .camera_name ) * 1000 ) / this .single_frame_duration_ms ;
3942
4043 List <String > raw_camera_points = this .plugin .getConfigCameras ().getPoints (this .camera_name );
44+ List <String > raw_camera_move_points = getMovementPoints (raw_camera_points );
4145
42- for (int i = 0 ; i < raw_camera_points .size () - 1 ; i ++) {
43- String raw_point = raw_camera_points .get (i );
44- String raw_point_next = raw_camera_points .get (i + 1 );
46+ for (int i = 0 ; i < raw_camera_move_points .size () - 1 ; i ++) {
47+ String raw_point = raw_camera_move_points .get (i );
48+ String raw_point_next = raw_camera_move_points .get (i + 1 );
4549
4650 Location point = Util .deserializeLocation (raw_point );
4751 Location point_next = Util .deserializeLocation (raw_point_next );
52+
4853
4954 this .camera_path_points .add (point );
50- for (int j = 0 ; j < max_points / (raw_camera_points .size () - 1 ) - 1 ; j ++) {
51- this .camera_path_points .add (translateLinear (point , point_next , j , max_points / (raw_camera_points .size () - 1 ) - 1 ));
55+ for (int j = 0 ; j < max_points / (raw_camera_move_points .size () - 1 ) - 1 ; j ++) {
56+ this .camera_path_points .add (translateLinear (point , point_next , j , max_points / (raw_camera_move_points .size () - 1 ) - 1 ));
57+ }
58+ }
59+
60+ int command_index = 0 ;
61+ for (String raw_point : raw_camera_points ) {
62+ String type = raw_point .split (":" , 2 )[0 ];
63+ String data = raw_point .split (":" , 2 )[1 ];
64+
65+ if (type .equalsIgnoreCase ("location" )) {
66+ command_index += 1 ;
67+ }
68+
69+ if (type .equalsIgnoreCase ("command" )) {
70+ int index = ((command_index ) * max_points / (raw_camera_move_points .size ()) - 1 );
71+ index = command_index == 0 ? 0 : index - 1 ;
72+ index = index < 0 ? 0 : index ;
73+ if (!this .camera_path_commands .containsKey (index )) this .camera_path_commands .put (index , new ArrayList <String >());
74+ this .camera_path_commands .get (index ).add (data );
75+ // this.camera_path_commands.put(index, raw_camera_points.get(0));
5276 }
5377 }
5478
5579 return this ;
5680 }
5781
82+ private List <String > getMovementPoints (List <String > raw_camera_points ) {
83+ List <String > output = new ArrayList <String >();
84+ for (String raw_point : raw_camera_points ) {
85+ String [] point_data = raw_point .split (":" , 2 );
86+ if (point_data [0 ].equalsIgnoreCase ("location" )) {
87+ output .add (point_data [1 ]);
88+ }
89+ }
90+ return output ;
91+ }
92+
5893 private Location translateLinear (Location point , Location point_next , int progress , int progress_max ) {
5994 if (!point .getWorld ().getUID ().toString ().equals (point_next .getWorld ().getUID ().toString ())) {
6095 return point_next ;
@@ -128,6 +163,13 @@ public void run() {
128163 Location next_point = camera_path_points .get (this .ticks + 1 );
129164
130165 player .teleport (camera_path_points .get (this .ticks ));
166+
167+ if (camera_path_commands .containsKey (this .ticks )) {
168+ for (String cmd : camera_path_commands .get (this .ticks )) {
169+ String command = cmd .replaceAll ("%player%" , player .getName ());
170+ Bukkit .dispatchCommand (Bukkit .getConsoleSender (), command );
171+ }
172+ }
131173
132174 player .setVelocity (calculateVelocity (current_pos , next_point ));
133175
@@ -154,13 +196,18 @@ public CameraHandler preview(Player player, int num, int preview_time) {
154196
155197 if (num > camera_points .size () - 1 )
156198 num = camera_points .size () - 1 ;
199+
200+ if (!camera_points .get (num ).split (":" , 2 )[0 ].equalsIgnoreCase ("location" )) {
201+ player .sendMessage (plugin .getPluginChatPrefix () + ChatColor .RED + "Point " + (num + 1 ) + " is not a location!" );
202+ return this ;
203+ }
157204
158205 player .sendMessage (plugin .getPluginChatPrefix () + ChatColor .GREEN + "Preview started of point " + (num + 1 ) + "!" );
159206 player .sendMessage (plugin .getPluginChatPrefix () + ChatColor .GREEN + "Ending in " + preview_time + " seconds." );
160207
161208 previous_gamemode = player .getGameMode ();
162209 previous_player_location = player .getLocation ();
163- Location point = Util .deserializeLocation (camera_points .get (num ));
210+ Location point = Util .deserializeLocation (camera_points .get (num ). split ( ":" , 2 )[ 1 ] );
164211 previous_invisible = player .isInvisible ();
165212
166213 plugin .player_camera_mode .put (player .getUniqueId (), PowerCamera .CAMERA_MODE .PREVIEW );
0 commit comments