1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-31 21:37:57 +01:00

Sort scoreboard by seting line number instead of jobs level

This commit is contained in:
Zrips 2016-12-02 18:40:20 +02:00
parent 40741d1a7d
commit 851d4600e1
7 changed files with 472 additions and 460 deletions

View File

@ -701,7 +701,6 @@ public class PlayerManager {
if (Jobs.getGCManager().useDynamicPayment)
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
return boost;

View File

@ -1,234 +1,237 @@
package com.gamingmesh.jobs.Signs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Skull;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.config.CommentedYamlConfiguration;
import com.gamingmesh.jobs.container.TopList;
public class SignUtil {
public SignInfo Signs = new SignInfo();
private Jobs plugin;
public SignUtil(Jobs plugin) {
this.plugin = plugin;
}
public SignInfo getSigns() {
return Signs;
}
// Sign file
public void LoadSigns() {
Signs.GetAllSigns().clear();
File file = new File(plugin.getDataFolder(), "Signs.yml");
YamlConfiguration f = YamlConfiguration.loadConfiguration(file);
if (!f.isConfigurationSection("Signs"))
return;
ConfigurationSection ConfCategory = f.getConfigurationSection("Signs");
ArrayList<String> categoriesList = new ArrayList<String>(ConfCategory.getKeys(false));
if (categoriesList.size() == 0)
return;
for (String category : categoriesList) {
ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category);
com.gamingmesh.jobs.Signs.Sign newTemp = new com.gamingmesh.jobs.Signs.Sign();
newTemp.setCategory(Integer.valueOf(category));
newTemp.setWorld(NameSection.getString("World"));
newTemp.setX(NameSection.getDouble("X"));
newTemp.setY(NameSection.getDouble("Y"));
newTemp.setZ(NameSection.getDouble("Z"));
newTemp.setNumber(NameSection.getInt("Number"));
newTemp.setJobName(NameSection.getString("JobName"));
newTemp.setSpecial(NameSection.getBoolean("Special"));
Signs.addSign(newTemp);
}
return;
}
// Signs save file
public void saveSigns() {
File f = new File(plugin.getDataFolder(), "Signs.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
conf.options().copyDefaults(true);
writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!");
if (!conf.isConfigurationSection("Signs"))
conf.createSection("Signs");
for (com.gamingmesh.jobs.Signs.Sign one : Signs.GetAllSigns()) {
String path = "Signs." + String.valueOf(one.GetCategory());
writer.set(path + ".World", one.GetWorld());
writer.set(path + ".X", one.GetX());
writer.set(path + ".Y", one.GetY());
writer.set(path + ".Z", one.GetZ());
writer.set(path + ".Number", one.GetNumber());
writer.set(path + ".JobName", one.GetJobName());
writer.set(path + ".Special", one.isSpecial());
}
try {
writer.save(f);
} catch (IOException e) {
e.printStackTrace();
}
return;
}
public boolean SignUpdate(String JobName) {
List<com.gamingmesh.jobs.Signs.Sign> Copy = new ArrayList<com.gamingmesh.jobs.Signs.Sign>(Signs.GetAllSigns().size());
for (com.gamingmesh.jobs.Signs.Sign foo : Signs.GetAllSigns()) {
Copy.add(foo);
}
int timelapse = 1;
for (com.gamingmesh.jobs.Signs.Sign one : Copy) {
String SignJobName = one.GetJobName();
if (JobName.equalsIgnoreCase(SignJobName)) {
String SignsWorld = one.GetWorld();
double SignsX = one.GetX();
double SignsY = one.GetY();
double SignsZ = one.GetZ();
int number = one.GetNumber() - 1;
List<TopList> PlayerList = new ArrayList<TopList>();
if (!JobName.equalsIgnoreCase("gtoplist")) {
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
} else {
PlayerList = Jobs.getJobsDAO().getGlobalTopList(number);
}
if (PlayerList.size() != 0) {
World world = Bukkit.getWorld(SignsWorld);
if (world == null)
continue;
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
Block block = nloc.getBlock();
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
Signs.GetAllSigns().remove(one);
saveSigns();
} else {
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
if (!one.isSpecial()) {
for (int i = 0; i < 4; i++) {
if (i >= PlayerList.size()) {
break;
}
String PlayerName = PlayerList.get(i).getPlayerName();
if (PlayerName != null && PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
PlayerName = PlayerNameStrip + "~";
}
if (PlayerName == null)
PlayerName = "Unknown";
String line = Jobs.getLanguage().getMessage("signs.List");
line = line.replace("[number]", String.valueOf(i + number + 1));
line = line.replace("[player]", PlayerName);
line = line.replace("[level]", String.valueOf(PlayerList.get(i).getLevel()));
sign.setLine(i, line);
}
sign.update();
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
} else {
String PlayerName = PlayerList.get(0).getPlayerName();
if (PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
PlayerName = PlayerNameStrip + "~";
}
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".1");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(0, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".2");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(1, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".3");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(2, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".4");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(3, line1);
sign.update();
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
}
timelapse++;
}
}
}
}
return true;
}
public void UpdateHead(final org.bukkit.block.Sign sign, final String Playername, final int timelapse) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();
BlockFace directionFacing = signMat.getFacing();
Location loc = sign.getLocation().clone();
loc.add(0, 1, 0);
if (Playername == null)
return;
Block block = loc.getBlock();
if (block == null || !(block.getState() instanceof Skull))
loc.add(directionFacing.getOppositeFace().getModX(), 0, directionFacing.getOppositeFace().getModZ());
block = loc.getBlock();
if (block == null || !(block.getState() instanceof Skull))
return;
Skull skull = (Skull) block.getState();
if (skull == null)
return;
skull.setOwner(Playername);
skull.update();
return;
}
}, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L);
}
}
package com.gamingmesh.jobs.Signs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Skull;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.meta.SkullMeta;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.config.CommentedYamlConfiguration;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.Debug;
public class SignUtil {
public SignInfo Signs = new SignInfo();
private Jobs plugin;
public SignUtil(Jobs plugin) {
this.plugin = plugin;
}
public SignInfo getSigns() {
return Signs;
}
// Sign file
public void LoadSigns() {
Signs.GetAllSigns().clear();
File file = new File(plugin.getDataFolder(), "Signs.yml");
YamlConfiguration f = YamlConfiguration.loadConfiguration(file);
if (!f.isConfigurationSection("Signs"))
return;
ConfigurationSection ConfCategory = f.getConfigurationSection("Signs");
ArrayList<String> categoriesList = new ArrayList<String>(ConfCategory.getKeys(false));
if (categoriesList.size() == 0)
return;
for (String category : categoriesList) {
ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category);
com.gamingmesh.jobs.Signs.Sign newTemp = new com.gamingmesh.jobs.Signs.Sign();
newTemp.setCategory(Integer.valueOf(category));
newTemp.setWorld(NameSection.getString("World"));
newTemp.setX(NameSection.getDouble("X"));
newTemp.setY(NameSection.getDouble("Y"));
newTemp.setZ(NameSection.getDouble("Z"));
newTemp.setNumber(NameSection.getInt("Number"));
newTemp.setJobName(NameSection.getString("JobName"));
newTemp.setSpecial(NameSection.getBoolean("Special"));
Signs.addSign(newTemp);
}
return;
}
// Signs save file
public void saveSigns() {
File f = new File(plugin.getDataFolder(), "Signs.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
conf.options().copyDefaults(true);
writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!");
if (!conf.isConfigurationSection("Signs"))
conf.createSection("Signs");
for (com.gamingmesh.jobs.Signs.Sign one : Signs.GetAllSigns()) {
String path = "Signs." + String.valueOf(one.GetCategory());
writer.set(path + ".World", one.GetWorld());
writer.set(path + ".X", one.GetX());
writer.set(path + ".Y", one.GetY());
writer.set(path + ".Z", one.GetZ());
writer.set(path + ".Number", one.GetNumber());
writer.set(path + ".JobName", one.GetJobName());
writer.set(path + ".Special", one.isSpecial());
}
try {
writer.save(f);
} catch (IOException e) {
e.printStackTrace();
}
return;
}
public boolean SignUpdate(String JobName) {
List<com.gamingmesh.jobs.Signs.Sign> Copy = new ArrayList<com.gamingmesh.jobs.Signs.Sign>(Signs.GetAllSigns().size());
for (com.gamingmesh.jobs.Signs.Sign foo : Signs.GetAllSigns()) {
Copy.add(foo);
}
int timelapse = 1;
for (com.gamingmesh.jobs.Signs.Sign one : Copy) {
String SignJobName = one.GetJobName();
if (JobName.equalsIgnoreCase(SignJobName)) {
String SignsWorld = one.GetWorld();
double SignsX = one.GetX();
double SignsY = one.GetY();
double SignsZ = one.GetZ();
int number = one.GetNumber() - 1;
List<TopList> PlayerList = new ArrayList<TopList>();
if (!JobName.equalsIgnoreCase("gtoplist")) {
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
} else {
PlayerList = Jobs.getJobsDAO().getGlobalTopList(number);
}
if (PlayerList.size() != 0) {
World world = Bukkit.getWorld(SignsWorld);
if (world == null)
continue;
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
Block block = nloc.getBlock();
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
Signs.GetAllSigns().remove(one);
saveSigns();
} else {
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
if (!one.isSpecial()) {
for (int i = 0; i < 4; i++) {
if (i >= PlayerList.size()) {
break;
}
String PlayerName = PlayerList.get(i).getPlayerName();
if (PlayerName != null && PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
PlayerName = PlayerNameStrip + "~";
}
if (PlayerName == null)
PlayerName = "Unknown";
String line = Jobs.getLanguage().getMessage("signs.List");
line = line.replace("[number]", String.valueOf(i + number + 1));
line = line.replace("[player]", PlayerName);
line = line.replace("[level]", String.valueOf(PlayerList.get(i).getLevel()));
sign.setLine(i, line);
}
sign.update();
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
} else {
String PlayerName = PlayerList.get(0).getPlayerName();
if (PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
PlayerName = PlayerNameStrip + "~";
}
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".1");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(0, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".2");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(1, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".3");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(2, line1);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".4");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
line1 = line1.replace("[player]", PlayerName);
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
sign.setLine(3, line1);
sign.update();
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
}
timelapse++;
}
}
}
}
return true;
}
public void UpdateHead(final org.bukkit.block.Sign sign, final String Playername, final int timelapse) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();
BlockFace directionFacing = signMat.getFacing();
Location loc = sign.getLocation().clone();
loc.add(0, 1, 0);
if (Playername == null)
return;
Block block = loc.getBlock();
if (block == null || !(block.getState() instanceof Skull))
loc.add(directionFacing.getOppositeFace().getModX(), 0, directionFacing.getOppositeFace().getModZ());
block = loc.getBlock();
if (block == null || !(block.getState() instanceof Skull))
return;
Skull skull = (Skull) block.getState();
if (skull == null)
return;
skull.setOwner(Playername);
skull.update();
return;
}
}, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L);
}
}

View File

@ -1,105 +1,105 @@
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.ChatColor;
public class gtop implements Cmd {
@Override
@JobCommand(600)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length != 1 && args.length != 0) {
Jobs.getCommandManager().sendUsage(sender, "gtop");
return true;
}
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
if (args.length > 0 && args[0].equalsIgnoreCase("clear")) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
return true;
}
int start = 0;
if (args.length == 1)
try {
start = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
return true;
}
if (start < 0)
start = 0;
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(start);
if (FullList.size() <= 0) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.gtop.error.nojob"));
return false;
}
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.topline"));
int i = start;
for (TopList One : FullList) {
i++;
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.list", "%number%", i, "%playername%", PlayerName, "%level%", One.getLevel(),
"%exp%", One.getExp()));
}
} else {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline"));
int i = start;
for (TopList One : FullList) {
i++;
String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.lines", "%number%", i, "%playername%", playername));
score.setScore(One.getLevel());
}
player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int from = start;
if (start >= 15)
from = start - 15;
int until = start + 15;
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);
}
return true;
}
}
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.ChatColor;
public class gtop implements Cmd {
@Override
@JobCommand(600)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length != 1 && args.length != 0) {
Jobs.getCommandManager().sendUsage(sender, "gtop");
return true;
}
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
if (args.length > 0 && args[0].equalsIgnoreCase("clear")) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
return true;
}
int start = 0;
if (args.length == 1)
try {
start = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
return true;
}
if (start < 0)
start = 0;
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(start);
if (FullList.size() <= 0) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.gtop.error.nojob"));
return false;
}
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.topline"));
int i = start;
for (TopList One : FullList) {
i++;
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.list", "%number%", i, "%playername%", PlayerName, "%level%", One.getLevel(),
"%exp%", One.getExp()));
}
} else {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline"));
int i = start;
int line = 16;
for (TopList One : FullList) {
i++;
line--;
String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel()));
score.setScore(line);
}
player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int from = start;
if (start >= 15)
from = start - 15;
int until = start + 15;
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);
}
return true;
}
}

View File

@ -1,114 +1,122 @@
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.ChatColor;
public class top implements Cmd {
@Override
@JobCommand(500)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length != 1 && args.length != 2) {
Jobs.getCommandManager().sendUsage(sender, "top");
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
Player player = (Player) sender;
if (args[0].equalsIgnoreCase("clear")) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
return true;
}
int start = 0;
if (args.length == 2)
try {
start = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
return true;
}
if (start < 0)
start = 0;
List<TopList> FullList = Jobs.getJobsDAO().toplist(args[0], start);
if (FullList.size() <= 0) {
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.top.error.nojob"));
return false;
}
Job job = Jobs.getJob(args[0]);
String jobName = args[0];
if (job != null)
jobName = job.getName();
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", jobName));
int i = start;
for (TopList One : FullList) {
i++;
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.list", "%number%", i, "%playername%", PlayerName, "%level%", One.getLevel(), "%exp%",
One.getExp()));
}
} else {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName));
int i = start;
for (TopList One : FullList) {
i++;
String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.lines", "%number%", i, "%playername%", playername));
score.setScore(One.getLevel());
}
player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int from = start;
if (start >= 15)
from = start - 15;
int until = start + 15;
String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.prev")
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top "
+ jobName + " " + from + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
"command.top.output.show", "[from]", from, "[until]", (from + 15)) + "\"}]}}}";
String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.next")
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top "
+ jobName + " " + until + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
"command.top.output.show", "[from]", (until + 1), "[until]", (until + 15)) + "\"}]}}}]";
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + prev + "," + next);
}
return true;
}
}
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.ChatColor;
public class top implements Cmd {
@Override
@JobCommand(500)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length != 1 && args.length != 2) {
Jobs.getCommandManager().sendUsage(sender, "top");
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
Player player = (Player) sender;
if (args[0].equalsIgnoreCase("clear")) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
return true;
}
int start = 0;
if (args.length == 2)
try {
start = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
return true;
}
if (start < 0)
start = 0;
if (Jobs.getJob(args[0]) == null) {
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.top.error.nojob"));
return false;
}
List<TopList> FullList = Jobs.getJobsDAO().toplist(args[0], start);
if (FullList.size() <= 0) {
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.noinfo"));
return false;
}
Job job = Jobs.getJob(args[0]);
String jobName = args[0];
if (job != null)
jobName = job.getName();
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", jobName));
int i = start;
for (TopList One : FullList) {
i++;
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.list", "%number%", i, "%playername%", PlayerName, "%level%", One.getLevel(), "%exp%",
One.getExp()));
}
} else {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName));
int i = start;
int line = 16;
for (TopList One : FullList) {
i++;
line--;
String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel()));
score.setScore(line);
}
player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int from = start;
if (start >= 15)
from = start - 15;
int until = start + 15;
String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.prev")
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top "
+ jobName + " " + from + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
"command.top.output.show", "[from]", from, "[until]", (from + 15)) + "\"}]}}}";
String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.next")
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top "
+ jobName + " " + until + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage(
"command.top.output.show", "[from]", (until + 1), "[until]", (until + 15)) + "\"}]}}}]";
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + prev + "," + next);
}
return true;
}
}

View File

@ -438,7 +438,7 @@ public class LanguageManager {
//c.get("scoreboard.clear", "&eIf you want to remove scoreboard, type &2/jobs top clear");
c.get("scoreboard.topline", "&2Top &e%jobname%");
c.get("scoreboard.gtopline", "&2Global top list");
c.get("scoreboard.lines", "&2%number%. &e%playername%");
c.get("scoreboard.line", "&2%number%. &e%playername% (&6%level%&e)");
Jobs.getGCManager().keys = new ArrayList<String>(c.getC().getConfigurationSection("signs.secondline").getKeys(false));

View File

@ -51,6 +51,7 @@ import com.gamingmesh.jobs.container.LogAmounts;
import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.container.PlayerPoints;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.TimeManage;
/**
@ -890,7 +891,6 @@ public abstract class JobsDAO {
prest.setInt(2, player.getUserId());
prest.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest);
}
@ -1335,7 +1335,7 @@ public abstract class JobsDAO {
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT DISTINCT(userid), `level`, `experience` FROM `" + prefix
prest = conn.prepareStatement("SELECT `userid`, `level`, `experience` FROM `" + prefix
+ "jobs` WHERE `job` LIKE ? ORDER BY `level` DESC, LOWER(experience) DESC LIMIT " + limit + ", 15;");
prest.setString(1, jobsname);
res = prest.executeQuery();
@ -1343,8 +1343,10 @@ public abstract class JobsDAO {
while (res.next()) {
Entry<String, PlayerInfo> info = Jobs.getPlayerManager().getPlayerInfoById(res.getInt("userid"));
if (info == null)
if (info == null){
Debug.D("Continue " + res.getInt("userid"));
continue;
}
if (info.getValue().getName() == null)
continue;

View File

@ -229,7 +229,7 @@ public class JobsListener implements Listener {
Sign sign = (Sign) block.getState();
String FirstLine = sign.getLine(0);
if (!FirstLine.equalsIgnoreCase(Jobs.getLanguage().getMessage("signs.topline")))
if (!ChatColor.stripColor(FirstLine).equalsIgnoreCase(ChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))))
return;
String command = ChatColor.stripColor(sign.getLine(1));
@ -242,7 +242,7 @@ public class JobsListener implements Listener {
}
Player player = event.getPlayer();
Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3)));
player.performCommand("jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3)));
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)