add toptime count

This commit is contained in:
Chris 2017-02-23 21:04:00 +01:00
parent 8b54357afc
commit b8c82e9567
5 changed files with 40 additions and 11 deletions

View File

@ -91,7 +91,7 @@ public class Config
return m_textPlayerNotFound;
}
private String m_textTopPlayerListHead = "This is the Top 5 player list.";
private String m_textTopPlayerListHead = "This is the Top %r player list.";
public String getTextTopPlayerListHead()
{
return m_textTopPlayerListHead;

View File

@ -29,10 +29,7 @@ public class DB
m_DBClass.update(_playerUUID, _newTime);
}
public List<String[]> getTopPlayers()
{
return m_DBClass.getTopPlayers();
}
public List<String[]> getTopPlayers(int _count){ return m_DBClass.getTopPlayers(_count); }
public int getPlayerTime(UUID _playerUUID)
{

View File

@ -30,6 +30,6 @@ public interface IDB
{
public void init(Plugin _plugin, Config _config);
public void update(UUID _playerUUID, int _newTime);
public List<String[]> getTopPlayers();
public List<String[]> getTopPlayers(int _count);
public int getPlayerTime(UUID _playerUUID);
}

View File

@ -57,9 +57,9 @@ public class MySQL implements IDB
m_MySqlTools.saveMySQLUpdate("REPLACE INTO playtime (`playeruuid`, `playtime`) VALUES ('" + _playerUUID.toString() + "', '" + _newTime + "')", new String[]{});
}
public List<String[]> getTopPlayers()
public List<String[]> getTopPlayers(int _count)
{
ResultSet _rs = m_MySqlTools.saveMySQLQuarry("SELECT * FROM playtime ORDER BY playtime DESC LIMIT 5", new String[]{});
ResultSet _rs = m_MySqlTools.saveMySQLQuarry("SELECT * FROM playtime ORDER BY playtime DESC LIMIT " + _count, new String[]{});
List<String[]> _returnList = new ArrayList<String[]>();
if(_rs != null)

View File

@ -68,19 +68,41 @@ public class Playtime extends JavaPlugin implements Listener
}}, 0, 1200);
}
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch(NumberFormatException e) {
return false;
} catch(NullPointerException e) {
return false;
}
// only got here if we didn't return false
return true;
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
if (cmd.getName().equalsIgnoreCase("toptime"))
{
int _count = 5;
if(args.length == 1)
{
if(isInteger(args[0]))
{
_count = Integer.parseInt(args[0]);
}
}
if (sender instanceof Player)
{
Player _player = (Player)sender;
if(_player.hasPermission("playtime.top"))
{
_player.sendMessage(getChatMessage(m_config.getTextTopPlayerListHead(), _player.getName(), 0, 0, true));
_player.sendMessage(getChatMessage(m_config.getTextTopPlayerListHead(), _player.getName(), 0, _count, true));
List<String[]> _topPlayers = m_db.getTopPlayers();
List<String[]> _topPlayers = m_db.getTopPlayers(_count);
int _rang = 1;
for (String[] _playerData: _topPlayers)
{
@ -93,7 +115,17 @@ public class Playtime extends JavaPlugin implements Listener
_player.sendMessage(getChatMessage(m_config.getTextNoPermission(), _player.getName(), 0, 0, true));
}
}else{
this.getLogger().info("Ey you bread! You cant display the playtime from the console!");
this.getLogger().info(getChatMessage(m_config.getTextTopPlayerListHead(), "", 0, _count, false));
List<String[]> _topPlayers = m_db.getTopPlayers(_count);
int _rang = 1;
for (String[] _playerData: _topPlayers)
{
if(_playerData.length >= 2)
{
this.getLogger().info(getChatMessage(m_config.getTextPlayerEntry(), _playerData[0], Integer.parseInt(_playerData[1]), _rang++, false));
}
}
}
}