mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-06 23:41:21 +01:00
Include 15 players into top list instead of 20
This commit is contained in:
parent
abd278dd09
commit
e20d470712
@ -16,6 +16,7 @@ import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.commands.JobCommand;
|
||||
import com.gamingmesh.jobs.container.TopList;
|
||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
import com.gamingmesh.jobs.stuff.RawMessage;
|
||||
|
||||
public class gtop implements Cmd {
|
||||
|
||||
@ -37,17 +38,17 @@ public class gtop implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
int page = 1;
|
||||
if (args.length == 1)
|
||||
try {
|
||||
start = Integer.parseInt(args[0]);
|
||||
page = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
if (page < 1)
|
||||
page = 1;
|
||||
|
||||
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(start);
|
||||
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(page * 15 - 15);
|
||||
if (FullList.size() <= 0) {
|
||||
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.gtop.error.nojob"));
|
||||
return false;
|
||||
@ -55,7 +56,7 @@ public class gtop implements Cmd {
|
||||
|
||||
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.topline"));
|
||||
int i = start;
|
||||
int i = page * 15 - 15;
|
||||
for (TopList One : FullList) {
|
||||
i++;
|
||||
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
|
||||
@ -71,7 +72,7 @@ public class gtop implements Cmd {
|
||||
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline"));
|
||||
int i = start;
|
||||
int i = page * 15 - 15;
|
||||
int line = 16;
|
||||
for (TopList One : FullList) {
|
||||
i++;
|
||||
@ -84,21 +85,15 @@ public class gtop implements Cmd {
|
||||
|
||||
Jobs.getScboard().addNew(player);
|
||||
|
||||
int from = start;
|
||||
if (start >= 15)
|
||||
from = start - 15;
|
||||
int until = start + 15;
|
||||
int prev = page < 2 ? 1 : page - 1;
|
||||
int next = page + 1;
|
||||
|
||||
String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.gtop.output.prev")
|
||||
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs gtop "
|
||||
+ from + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
|
||||
"command.gtop.output.show", "[from]", from, "[until]", (from + 15)) + "\"}]}}}";
|
||||
String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.gtop.output.next")
|
||||
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs gtop "
|
||||
+ until + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
|
||||
"command.gtop.output.show", "[from]", (until + 1), "[until]", (until + 15)) + "\"}]}}}]";
|
||||
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + prev + "," + next);
|
||||
RawMessage rm = new RawMessage();
|
||||
rm.add(Jobs.getLanguage().getMessage("command.gtop.output.prev"),
|
||||
Jobs.getLanguage().getMessage("command.gtop.output.show", "[from]", prev * 15 - 15, "[until]", (prev * 15)), "jobs gtop " + prev);
|
||||
rm.add(Jobs.getLanguage().getMessage("command.gtop.output.next"),
|
||||
Jobs.getLanguage().getMessage("command.gtop.output.show", "[from]", (next * 15), "[until]", (next * 15 + 15)), "jobs gtop " + next);
|
||||
rm.show(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ public abstract class JobsDAO {
|
||||
try {
|
||||
|
||||
prest = conn.prepareStatement("SELECT userid, COUNT(*) AS amount, sum(level) AS totallvl FROM `" + prefix
|
||||
+ "jobs` GROUP BY userid ORDER BY totallvl DESC LIMIT " + start + ",20;");
|
||||
+ "jobs` GROUP BY userid ORDER BY totallvl DESC LIMIT " + start + ",100;");
|
||||
res = prest.executeQuery();
|
||||
|
||||
while (res.next()) {
|
||||
@ -726,6 +726,8 @@ public abstract class JobsDAO {
|
||||
continue;
|
||||
TopList top = new TopList(info, res.getInt("totallvl"), 0);
|
||||
names.add(top);
|
||||
if (names.size() >= 15)
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
118
src/main/java/com/gamingmesh/jobs/stuff/RawMessage.java
Normal file
118
src/main/java/com/gamingmesh/jobs/stuff/RawMessage.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.gamingmesh.jobs.stuff;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RawMessage {
|
||||
|
||||
List<String> parts = new ArrayList<String>();
|
||||
List<String> cleanParts = new ArrayList<String>();
|
||||
String combined = "";
|
||||
String combinedClean = "";
|
||||
|
||||
public void clear() {
|
||||
parts = new ArrayList<String>();
|
||||
cleanParts = new ArrayList<String>();
|
||||
combined = "";
|
||||
combinedClean = "";
|
||||
}
|
||||
|
||||
public RawMessage add(String text) {
|
||||
return add(text, null, null, null, null);
|
||||
}
|
||||
|
||||
public RawMessage add(String text, String hoverText) {
|
||||
return add(text, hoverText, null, null, null);
|
||||
}
|
||||
|
||||
public RawMessage add(String text, String hoverText, String command) {
|
||||
return add(text, hoverText, command, null, null);
|
||||
}
|
||||
|
||||
public RawMessage add(String text, String hoverText, String command, String suggestion) {
|
||||
return add(text, hoverText, command, suggestion, null);
|
||||
}
|
||||
|
||||
public RawMessage add(String text, String hoverText, String command, String suggestion, String url) {
|
||||
if (text == null)
|
||||
return this;
|
||||
String f = "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', text) + "\"";
|
||||
String last = ChatColor.getLastColors(ChatColor.translateAlternateColorCodes('&', text));
|
||||
if (last != null && !last.isEmpty()) {
|
||||
ChatColor color = ChatColor.getByChar(last.replace("<EFBFBD>", ""));
|
||||
if (color != null) {
|
||||
f += ",\"color\":\"" + color.name().toLowerCase() + "\"";
|
||||
}
|
||||
}
|
||||
if (hoverText != null)
|
||||
f += ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', hoverText) + "\"}]}}";
|
||||
if (suggestion != null)
|
||||
f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + suggestion + "\"}";
|
||||
|
||||
if (url != null) {
|
||||
f += ",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}";
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
if (!command.startsWith("/"))
|
||||
command = "/" + command;
|
||||
f += ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + command + "\"}";
|
||||
}
|
||||
f += "}";
|
||||
parts.add(f);
|
||||
cleanParts.add(ChatColor.translateAlternateColorCodes('&', text));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RawMessage combine() {
|
||||
String f = "";
|
||||
for (String part : parts) {
|
||||
if (f.isEmpty())
|
||||
f = "[\"\",";
|
||||
else
|
||||
f += ",";
|
||||
f += part;
|
||||
}
|
||||
if (!f.isEmpty())
|
||||
f += "]";
|
||||
combined = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RawMessage combineClean() {
|
||||
String f = "";
|
||||
for (String part : cleanParts) {
|
||||
f += part;
|
||||
}
|
||||
combinedClean = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RawMessage show(Player player) {
|
||||
if (combined.isEmpty())
|
||||
combine();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + combined);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RawMessage show(CommandSender sender) {
|
||||
if (combined.isEmpty())
|
||||
combine();
|
||||
if (sender instanceof Player)
|
||||
show((Player) sender);
|
||||
else
|
||||
sender.sendMessage(this.combineClean().combinedClean);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRaw() {
|
||||
if (combined.isEmpty())
|
||||
combine();
|
||||
return combined;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user