@@ -40,30 +40,31 @@ public abstract class AbstractPlotCommand extends Command {
4040    public  void  run (CommandEvent  event ) {
4141        PresetBuilder  preset  = new  PresetBuilder ();
4242        try  {
43-             ResultSet   resultTablePlot  = getPlot (event );
43+             Plot   plot  = getPlot (event );
4444            EmbedBuilder  embed  = preset .getEmbed ();
4545
46-             if  (resultTablePlot  == null  || ! resultTablePlot . next () ) {
46+             if  (plot  == null ) {
4747                throw  new  IllegalStateException ("Plot not found" );
4848            }
49-             int  plotID  = resultTablePlot . getInt ( "id" );
49+             int  plotID  = plot . id ( );
5050            preset .withPreset (
5151                    new  InformativeReply (InformativeReplyType .INFO , String .format ("Plot Information (%s)" , plotID ), null )
5252            );
5353
54-             @ Nullable  String  handle  = resultTablePlot . getString ( " handle" 
55-             @ Nullable  String  description  = resultTablePlot . getString ( " description" 
56-             PlotSize  size  = PlotSize . fromID ( resultTablePlot . getInt ( "plotsize" ) -  1 );
54+             @ Nullable  String  handle  = plot . handle ( );
55+             @ Nullable  String  description  = plot . description ( );
56+             PlotSize  size  = plot . plotSize ( );
5757
5858            embed .setTitle (handle  == null  ? String .format ("Plot Information (%s)" , plotID ) : String .format ("Plot Information (%s) (%s)" , handle , plotID ));
5959            embed .setDescription (description );
60-             embed .addField ("Name" , StringUtil .fromMiniMessage (resultTablePlot .getString ("name" )), true );
61-             embed .addField ("Owner" , resultTablePlot .getString ("owner_name" ), true );
62-             embed .addField ("Node" , "Node "  + resultTablePlot .getInt ("node" ), true );
60+             embed .addField ("Name" , StringUtil .fromMiniMessage (plot .name ()), true );
61+             embed .addField ("Owner" , plot .ownerName (), true );
62+             boolean  privateNode  = plot .node () >= 1000 ;
63+             embed .addField ("Node" , (privateNode  ? "Private "  : "" ) + "Node "  + (privateNode  ? plot .node () - 1000  : plot .node ()), true );
6364            embed .addField ("Plot Size" , StringUtil .smartCaps (size .name ()), true );
6465
6566            // Creates a list of tags that the plot has 
66-             String  tags  = resultTablePlot . getString ( " tags" 
67+             String  tags  = plot . tags ( );
6768            if  (tags .equals ("none" )) {
6869                embed .addField ("Plot Tags" , "None" , true );
6970            } else  {
@@ -74,22 +75,19 @@ public void run(CommandEvent event) {
7475                embed .addField ("Plot Tags" , StringUtil .listView ("> " , true , tagList .toArray (new  String [0 ])), true );
7576            }
7677
77-             int  weeksTillClear  = resultTablePlot .getInt ("immunity_level" );
78-             LocalDate  activeTime  = resultTablePlot .getDate ("active_time" ).toLocalDate ();
79-             LocalDate  clearDate  = activeTime .plus (weeksTillClear , ChronoUnit .WEEKS );
78+             LocalDate  activeTime  = plot .activeTime ();
8079
81-             embed .addField ("Auto Clear Date" , FormatUtil .formatDate (clearDate ) + String .format (" (%s weeks)" , ChronoUnit .WEEKS .between (activeTime , clearDate )), true );
8280            embed .addField ("Last Active Date" , FormatUtil .formatDate (activeTime ), true );
83-             embed .addField ("Whitelisted" , ( resultTablePlot . getInt ( "whitelist" ) ==  1 ) + "" , true );
84-             embed .addField ("Player Count" , FormatUtil .formatNumber (resultTablePlot . getInt ( "player_count" )), true );
85-             embed .addField ("Current Votes" , FormatUtil .formatNumber (resultTablePlot . getInt ( " votes" true );
81+             embed .addField ("Whitelisted" , plot . whitelisted ( ) + "" , true );
82+             embed .addField ("Player Count" , FormatUtil .formatNumber (plot . playerCount ( )), true );
83+             embed .addField ("Current Votes" , FormatUtil .formatNumber (plot . votes ( )), true );
8684
87-             int  x  = resultTablePlot . getInt ( "xmin" ) + (size .getSize () / 2 );
88-             int  z  = resultTablePlot . getInt ( "zmin" ) + (size .getSize () / 2 );
85+             int  x  = plot . xMin ( ) + (size .getSize () / 2 );
86+             int  z  = plot . zMin ( ) + (size .getSize () / 2 );
8987            embed .addField ("Plot Center" , String .format ("[%s, 50, %s]" , x , z ), true );
9088
9189            // Creates the icon for the plot 
92-             String  plotIcon  = resultTablePlot . getString ( " icon" 
90+             String  plotIcon  = plot . icon ( );
9391            // Plot head icons start with the character h. 
9492            if  (plotIcon .startsWith ("h" )) {
9593                embed .setThumbnail (Util .getPlayerHead (plotIcon .substring (1 )));
@@ -100,35 +98,35 @@ public void run(CommandEvent event) {
10098                event .getReplyHandler ().replyA (preset ).addFiles (FileUpload .fromData (mcItem )).queue ();
10199            }
102100
103-         } catch  (SQLException  |  IllegalStateException  e ) {
101+         } catch  (IllegalStateException  e ) {
104102            preset .withPreset (
105103                    new  InformativeReply (InformativeReplyType .ERROR , "Plot was not found." )
106104            );
107105            event .reply (preset );
108106        }
109107    }
110108
111-     public  abstract  ResultSet  getPlot (CommandEvent  event );
109+     public  abstract  @ Nullable   Plot  getPlot (CommandEvent  event );
112110
113-     
114-     private  enum  PlotSize  {
115-         BASIC (51 ),
116-         LARGE (101 ),
117-         MASSIVE (301 ),
118-         MEGA (1001 );
119-         
120-         private  final  int  size ;
121-         
122-         PlotSize (int  size ) {
123-             this .size  = size ;
124-         }
125-         
126-         public  int  getSize () {
127-             return  size ;
128-         }
129-         
130-         public  static  PlotSize  fromID (int  id ) {
131-             return  PlotSize .values ()[id ];
132-         }
111+     protected  Plot  mapResultSetToPlot (final  ResultSet  rs ) throws  SQLException  {
112+         return  new  Plot (
113+                 rs .getInt ("id" ),
114+                 rs .getString ("handle" ),
115+                 rs .getString ("description" ),
116+                 rs .getString ("name" ),
117+                 rs .getString ("owner_name" ),
118+                 rs .getInt ("node" ),
119+                 PlotSize .fromID (rs .getInt ("plotsize" ) - 1 ),
120+                 rs .getString ("tags" ),
121+                 rs .getInt ("immunity_level" ),
122+                 rs .getDate ("active_time" ).toLocalDate (),
123+                 rs .getInt ("whitelist" ) == 1 ,
124+                 rs .getInt ("player_count" ),
125+                 rs .getInt ("votes" ),
126+                 rs .getInt ("xmin" ),
127+                 rs .getInt ("zmin" ),
128+                 rs .getString ("icon" )
129+         );
133130    }
131+ 
134132}
0 commit comments