Skip to content

Commit

Permalink
Changed the top list of likes from the default 10 to 5, and the numbe…
Browse files Browse the repository at this point in the history
…r of cases can be specified at the same time

Sign list command can be narrowed down by player
いいねトップリストをディフォルト10件から5件へ変更、同時に件数を指定できるようにした
看板リストをプレイヤーで絞り込めるようにした
  • Loading branch information
kumaisu committed Oct 7, 2019
1 parent 6cb88dc commit 72204d7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
4 changes: 2 additions & 2 deletions buildNumber.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Sat Oct 05 22:17:15 JST 2019
buildNumber=6
#Tue Oct 08 02:09:11 JST 2019
buildNumber=1
3 changes: 2 additions & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>ThisLike</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<description>This Like Event Control plugin</description>
<scm>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>ThisLike</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<description>This Like Event Control plugin</description>
<packaging>jar</packaging>
<properties>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/mycompany/thislike/command/ThislikeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ public boolean onCommand( CommandSender sender, Command cmd, String commandLabel

switch ( commandString ) {
case "top":
SignData.LikeTop( player );
int lineSet;
try {
lineSet = Integer.valueOf( itemName );
} catch ( NumberFormatException e ) {
lineSet = 5;
}
SignData.LikeTop( player, lineSet );
return true;
case "list":
SignData.SignList( player );
SignData.SignList( player, ( ( args.length > 1 ) ? args[1] : "" ) );
return true;
case "status":
instance.config.Status( player );
Expand All @@ -60,7 +66,8 @@ public boolean onCommand( CommandSender sender, Command cmd, String commandLabel
return true;
case "help":
Tools.Prt( player, ChatColor.GREEN + "/ThisLike Command List", programCode );
Tools.Prt( player, ChatColor.YELLOW + "list : " + ChatColor.WHITE + "いいね看板リスト", programCode );
Tools.Prt( player, ChatColor.YELLOW + "top [num] : " + ChatColor.WHITE + "いいねトップリスト", programCode );
Tools.Prt( player, ChatColor.YELLOW + "list [player] : " + ChatColor.WHITE + "いいね看板リスト", programCode );
Tools.Prt( player, ChatColor.YELLOW + "status : " + ChatColor.WHITE + "システム設定閲覧", programCode );
Tools.Prt( player, ChatColor.YELLOW + "Console [Mode] : " + ChatColor.WHITE + "コンソールデバッグ設定 [max,full,normal,none]", programCode );
Tools.Prt( player, ChatColor.YELLOW + "reload : " + ChatColor.WHITE + "Configリロード", programCode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public static void printLiker( Player player, int ID, String Title, boolean hasO
TempInv.addItem( getPlayerHead( player, key, Lore ) );
} );

inv.put( player.getUniqueId(), TempInv );
player.openInventory( TempInv );
inv.put( player.getUniqueId(), TempInv );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void AddSQL( Player player, int ID ) {
Database.LikeName = player.getName();
Database.StampDate = new Date();

Tools.Prt( "Like Add Data to SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Like Add Data to SQL Success.", Tools.consoleMode.max , programCode );
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error AddToSQL" + e.getMessage(), programCode );
}
Expand All @@ -76,7 +76,7 @@ public static boolean DelPlayerSQL( int ID, Player player ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
PreparedStatement preparedStatement = con.prepareStatement( sql );
preparedStatement.executeUpdate();
Tools.Prt( "Like Delete Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Like Delete Data from SQL Success.", Tools.consoleMode.max , programCode );
con.close();
return true;
} catch ( SQLException e ) {
Expand All @@ -97,7 +97,7 @@ public static boolean DelSQL( int ID ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
PreparedStatement preparedStatement = con.prepareStatement( sql );
preparedStatement.executeUpdate();
Tools.Prt( "Like Delete Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Like Delete Data from SQL Success.", Tools.consoleMode.max , programCode );
con.close();
return true;
} catch ( SQLException e ) {
Expand All @@ -123,7 +123,7 @@ public static boolean GetSQL( int ID ) {
Database.LikeUUID = fromString( rs.getString( "uuid" ) );
Database.LikeName = rs.getString( "name" );
Database.StampDate = rs.getTimestamp( "date" );
Tools.Prt( "Like Get Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Like Get Data from SQL Success.", Tools.consoleMode.max , programCode );
retStat = true;
}
con.close();
Expand All @@ -149,7 +149,7 @@ public static boolean hasSQL( int ID, Player player ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
ResultSet rs = stmt.executeQuery( sql );
if ( rs.next() ) {
Tools.Prt( "Get Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Get Data from SQL Success.", Tools.consoleMode.max , programCode );
retStat = true;
}
con.close();
Expand Down Expand Up @@ -181,7 +181,7 @@ public static Map< String, Date > listSQL( int ID ) {
Tools.Prt( "get Liker : " + liker, Tools.consoleMode.max, programCode );
likeP.put( liker, likeD );
}
Tools.Prt( "get Like Player List from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "get Like Player List from SQL Success.", Tools.consoleMode.max , programCode );
con.close();
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error listSQL" + e.getMessage(), programCode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class MySQLControl {
public static void connect() {
if ( Database.dataSource != null ) {
if ( Database.dataSource.isClosed() ) {
Tools.Prt( ChatColor.RED + "database closed.", Tools.consoleMode.full, programCode );
Tools.Prt( ChatColor.RED + "database closed.", programCode );
disconnect();
} else {
Tools.Prt( ChatColor.AQUA + "dataSource is not null", Tools.consoleMode.max, programCode );
Tools.Prt( ChatColor.AQUA + "dataSource is not null", programCode );
return;
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public static void TableUpdate() {
preparedStatement = con.prepareStatement( sql );
preparedStatement.executeUpdate();

Tools.Prt( ChatColor.AQUA + "dataSource Open Success.", Tools.consoleMode.full, programCode );
Tools.Prt( ChatColor.AQUA + "dataSource Open Success.", programCode );
con.close();
} catch( SQLException e ) {
Tools.Prt( ChatColor.RED + "Connection Error : " + e.getMessage(), programCode);
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/com/mycompany/thislike/database/SignData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import java.sql.Statement;
import java.text.SimpleDateFormat;
import static java.util.UUID.fromString;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.mycompany.kumaisulibraries.Tools;
import static com.mycompany.thislike.config.Config.programCode;
import org.bukkit.Bukkit;

/**
* @author sugichan
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void AddSQL( Player player, Location LOC ) {
Database.SignDate = new Date();
Database.LikeNum = 0;

Tools.Prt( "Sign Add Data to SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Sign Add Data to SQL Success.", Tools.consoleMode.max, programCode );
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error AddToSQL" + e.getMessage(), programCode );
}
Expand All @@ -83,7 +83,7 @@ public static boolean DelSQL( int ID ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
PreparedStatement preparedStatement = con.prepareStatement( sql );
preparedStatement.executeUpdate();
Tools.Prt( "Sign Delete Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Sign Delete Data from SQL Success.", Tools.consoleMode.max, programCode );
con.close();
return true;
} catch ( SQLException e ) {
Expand Down Expand Up @@ -119,7 +119,7 @@ public static boolean GetSQL( Location LOC ) {
Database.OwnerName = rs.getString( "name" );
Database.SignDate = rs.getTimestamp( "date" );
Database.LikeNum = rs.getInt( "likenum" );
Tools.Prt( "Sign Get Data from SQL Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Sign Get Data from SQL Success.", Tools.consoleMode.max, programCode );
retStat = true;
}
con.close();
Expand All @@ -141,7 +141,7 @@ public static void incLike( int ID ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
PreparedStatement preparedStatement = con.prepareStatement(sql);
preparedStatement.executeUpdate();
Tools.Prt( "Sign Like Inc Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Sign Like Inc Success.", Tools.consoleMode.max, programCode );
con.close();
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error Add LikeNum : " + e.getMessage(), programCode );
Expand All @@ -159,7 +159,7 @@ public static void subLike( int ID ) {
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );
PreparedStatement preparedStatement = con.prepareStatement(sql);
preparedStatement.executeUpdate();
Tools.Prt( "Sign Like Sub Success.", Tools.consoleMode.full , programCode );
Tools.Prt( "Sign Like Sub Success.", Tools.consoleMode.max, programCode );
con.close();
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error sub LikeNum : " + e.getMessage(), programCode );
Expand All @@ -170,12 +170,17 @@ public static void subLike( int ID ) {
* イイネ看板リスト
*
* @param player
* @param name
*/
public static void SignList( Player player ) {
public static void SignList( Player player, String name ) {
try ( Connection con = Database.dataSource.getConnection() ) {
Tools.Prt( player, ChatColor.GREEN + "List for Signs ...", programCode );
Statement stmt = con.createStatement();
String sql = "SELECT * FROM sign ORDER BY world ASC;";
String sql = "SELECT * FROM sign";
if ( !"".equals( name ) ) { sql += " WHERE name = '" + name + "'"; }
sql += " ORDER BY world ASC;";
Tools.Prt( "SQL : " + sql, Tools.consoleMode.max , programCode );

ResultSet rs = stmt.executeQuery( sql );
while( rs.next() ) {
Tools.Prt( player,
Expand Down Expand Up @@ -203,16 +208,17 @@ public static void SignList( Player player ) {
* イイネ看板リスト
*
* @param player
* @param LineSet
*/
public static void LikeTop( Player player ) {
public static void LikeTop( Player player, int LineSet ) {
try ( Connection con = Database.dataSource.getConnection() ) {
Tools.Prt( player, ChatColor.GREEN + "Like Top List ...", programCode );
Statement stmt = con.createStatement();
String sql = "SELECT * FROM sign ORDER BY likenum DESC;";
ResultSet rs = stmt.executeQuery( sql );

int Rank = 0;
while( rs.next() && ( Rank<10 ) ) {
while( rs.next() && ( Rank < LineSet ) ) {
Rank++;
Tools.Prt( player,
ChatColor.WHITE + String.format( "%3d", Rank ) + ": " +
Expand All @@ -228,7 +234,7 @@ public static void LikeTop( Player player ) {
);
}
con.close();
Tools.Prt( player, ChatColor.GREEN + "Top List [EOF]", programCode );
if ( Rank == 0 ) Tools.Prt( player, ChatColor.GREEN + "Top List [EOF]", programCode );
} catch ( SQLException e ) {
Tools.Prt( ChatColor.RED + "Error LikeTop : " + e.getMessage(), programCode );
}
Expand Down

0 comments on commit 72204d7

Please sign in to comment.