2626import java .util .HashMap ;
2727import java .util .UUID ;
2828
29- public class WarpaliciousCommand implements CommandExecutor
30- {
29+ public class WarpaliciousCommand implements CommandExecutor {
3130
3231 private WarpaliciousPlugin plugin ;
3332 private Strings str ;
3433
35- public WarpaliciousCommand (WarpaliciousPlugin pl , Strings instance )
36- {
34+ public WarpaliciousCommand (WarpaliciousPlugin pl , Strings instance ) {
3735 str = instance ;
3836 plugin = pl ;
3937 }
4038
41- public boolean onCommand (CommandSender sender , Command cmd , String label , String [] args )
42- {
43- if (args .length == 1 )
44- {
45- if (args [0 ].equalsIgnoreCase ("reloadmessages" ) && str .checkPermission (sender , str .universalPerm ))
46- {
39+ public boolean onCommand (CommandSender sender , Command cmd , String label , String [] args ) {
40+ if (args .length == 1 ) {
41+ if (args [0 ].equalsIgnoreCase ("reloadmessages" ) && str .checkPermission (sender , str .universalPerm )) {
4742 plugin .getStrings ().loadMessages ();
4843 sender .sendMessage (str .prefix + " Succesfully reloaded messages!" );
4944 return true ;
50- }
51- else
52- {
45+ } else {
5346 sender .sendMessage (str .getUsage (cmd , label ));
5447 return true ;
5548 }
56- }
57- else if (args .length == 2 )
58- {
59- if (args [0 ].equalsIgnoreCase ("import" ))
60- {
61- if (args [1 ].equalsIgnoreCase ("mywarp" ))
62- {
63- if (str .checkPermission (sender , str .universalPerm ))
64- {
49+ } else if (args .length == 2 ) {
50+ if (args [0 ].equalsIgnoreCase ("import" )) {
51+ if (str .checkPermission (sender , str .universalPerm )) {
52+ if (args [1 ].equalsIgnoreCase ("mywarp" )) {
6553 MyWarpPlugin mwp = (MyWarpPlugin ) plugin .getServer ().getPluginManager ().getPlugin ("MyWarp" );
66- if (mwp == null )
67- {
54+ if (mwp == null ) {
6855 sender .sendMessage ("The MyWarp plugin is not installed on this server!" );
6956 return true ;
7057 }
71- try
72- {
58+ try {
7359 Field myWarpField = mwp .getClass ().getDeclaredField ("myWarp" );
7460 myWarpField .setAccessible (true );
7561 EventfulPopulatableWarpManager ewm = (EventfulPopulatableWarpManager ) ((MyWarp ) myWarpField .get (mwp )).getWarpManager ();
@@ -91,8 +77,7 @@ else if (args.length == 2)
9177 int addedWarps = 0 ;
9278 int failedWarps = 0 ;
9379 int totalWarps = warpMap .size ();
94- for (String wName : warpMap .keySet ())
95- {
80+ for (String wName : warpMap .keySet ()) {
9681
9782 Object initialObj = warpMap .get (wName );
9883
@@ -140,79 +125,92 @@ else if (args.length == 2)
140125
141126 HashMap <Flag , Boolean > defFlags = plugin .getWarpHandler ().getDefaultFlags ();
142127
143- if (warpMyWarp .getType () == Warp .Type .PRIVATE )
144- {
128+ if (warpMyWarp .getType () == Warp .Type .PRIVATE ) {
145129 defFlags .put (Flag .PRIVATE , true );
146130 }
147131
148- if (plugin .getWarpHandler ().getWarp (wName ) == null )
149- {
150- new nl .datdenkikniet .warpalicious .handling .Warp (plugin , warpMyWarp .getCreator (), loc , warpMyWarp .getName (), defFlags , plugin .getWarpHandler (), warpMyWarp .getVisits (), invitedPlayers , wName );
132+ if (plugin .getWarpHandler ().getWarp (wName ) == null ) {
133+ new nl .datdenkikniet .warpalicious .handling .Warp (plugin , warpMyWarp .getCreator (), loc , warpMyWarp .getName (), defFlags , warpMyWarp .getVisits (), invitedPlayers );
151134 System .out .println ("Imported " + (defFlags .get (Flag .PRIVATE ) ? "private" : "" ) + " warp with name " + wName + " at location x:" + x + ", y:" + y + ", z:" + z + ", yaw:" + yaw + ", pitch:" + pitch + " and " + invitedPlayers .size () + " invited players" );
152135 addedWarps ++;
153- }
154- else
155- {
136+ } else {
156137 System .out .println ("Failed to add import warp " + wName + ". A warp with that name already exists!" );
157138 failedWarps ++;
158139 }
159140 }
160141 sender .sendMessage ("Attempting to import " + totalWarps + " warps..." );
161142 sender .sendMessage ("Imported " + addedWarps + " warps from mywarp." );
162143 sender .sendMessage ("Failed to add " + failedWarps + " warps (check the console for more information)." );
163- }
164- catch (Exception ex )
165- {
144+ } catch (Exception ex ) {
166145 ex .printStackTrace ();
167146 sender .sendMessage ("Something went wrong!" );
168147 return true ;
169148 }
170149 return true ;
171- }
172- else
173- {
174- sender .sendMessage (str .noperm );
175- return true ;
176- }
177- }
178- else if (args [1 ].equalsIgnoreCase ("warptastic" )){
179- try
180- {
181- warptastic wp = (warptastic ) plugin .getServer ().getPluginManager ().getPlugin ("warptastic" );
182- Field serviceField = wp .getClass ().getDeclaredField ("service" );
183- serviceField .setAccessible (true );
184- DBConnection service = (DBConnection ) serviceField .get (wp );
185-
186- Connection stmt = service .getConnection ();
187- Statement rs = stmt .createStatement ();
188- ResultSet target = rs .executeQuery ("PRAGMA table_info(W_Warps);" );
189-
190- while (target .next ())
191- {
192- System .out .println (target .toString ());
150+ } else if (args [1 ].equalsIgnoreCase ("warptastic" )) {
151+ int addedWarps = 0 ;
152+ int failedWarps = 0 ;
153+ int totalWarps = 0 ;
154+ try {
155+ warptastic wp = (warptastic ) plugin .getServer ().getPluginManager ().getPlugin ("warptastic" );
156+ Field serviceField = wp .getClass ().getDeclaredField ("service" );
157+ serviceField .setAccessible (true );
158+ DBConnection service = (DBConnection ) serviceField .get (wp );
159+
160+ Connection stmt = service .getConnection ();
161+ Statement rs = stmt .createStatement ();
162+ ResultSet target = rs .executeQuery ("SELECT * FROM W_Warps;" );
163+ while (target .next ()) {
164+ totalWarps ++;
165+ String name = target .getString ("warpname" );
166+ UUID owner = Bukkit .getOfflinePlayer (target .getString ("owner" )).getUniqueId ();
167+ String world = target .getString ("world" );
168+ double x = target .getDouble ("x" );
169+ double y = target .getDouble ("y" );
170+ double z = target .getDouble ("z" );
171+ float yaw = target .getFloat ("f" );
172+ float pitch = target .getFloat ("p" );
173+ boolean isPrivate = target .getBoolean ("privacy" );
174+ int timesWarpedTo = target .getInt ("popularity" );
175+ HashMap <Flag , Boolean > defFlags = plugin .getWarpHandler ().getDefaultFlags ();
176+ if (isPrivate ) {
177+ defFlags .put (Flag .PRIVATE , true );
178+ }
179+ if (plugin .getWarpHandler ().getWarp (name ) == null ) {
180+ new nl .datdenkikniet .warpalicious .handling .Warp (plugin , owner , new Location (Bukkit .getWorld (world ), x , y , z , yaw , pitch ), name , defFlags , timesWarpedTo , new ArrayList <>());
181+ System .out .println ("Imported " + (defFlags .get (Flag .PRIVATE ) ? "private" : "" ) + " warp with name " + name + " at location x:" + x + ", y:" + y + ", z:" + z + ", yaw:" + yaw + ", pitch:" + pitch );
182+ addedWarps ++;
183+ } else {
184+ System .out .println ("Failed to add import warp " + name + ". A warp with that name already exists!" );
185+ failedWarps ++;
186+ }
187+ }
188+ target .close ();
189+ rs .close ();
190+ plugin .getWarpHandler ().saveWarps ();
191+ sender .sendMessage ("Ateempted to import " + totalWarps + " warps..." );
192+ sender .sendMessage ("Imported " + addedWarps + " warps from warptastic." );
193+ sender .sendMessage ("Failed to add " + failedWarps + " warps (check the console for more information)." );
194+ return true ;
195+ } catch (Exception ex ) {
196+ ex .printStackTrace ();
197+ sender .sendMessage ("Something went wrong while trying to import warptastic warps!" );
198+ return true ;
193199 }
194- target .close ();
195- rs .close ();
196- return true ;
197- } catch (Exception ex ){
198- ex .printStackTrace ();
200+ } else {
201+ sender .sendMessage (str .getUsage (cmd , label ));
199202 return true ;
200203 }
201- }
202- else
203- {
204- sender .sendMessage (str .getUsage (cmd , label ));
204+ } else {
205+ sender .sendMessage (str .noperm );
205206 return true ;
206207 }
207- }
208- else
209- {
208+ } else {
210209 sender .sendMessage (str .getUsage (cmd , label ));
211210 return true ;
212211 }
213- }
214- else
215- {
212+
213+ } else {
216214 sender .sendMessage (str .prefix + " This server is running Warpalicious version " + plugin .getDescription ().getVersion () + " by datdenkikniet." );
217215 return true ;
218216 }
0 commit comments