Hotfix & /ftop
This commit is contained in:
parent
6202e30522
commit
4a7d7379b0
4 changed files with 42 additions and 19 deletions
|
@ -71,9 +71,9 @@ public class ChatPlayer extends TBMCPlayerBase {
|
||||||
public String GetFormattedFlair(boolean noformats) {
|
public String GetFormattedFlair(boolean noformats) {
|
||||||
int time = FlairTime().get();
|
int time = FlairTime().get();
|
||||||
if (time == FlairTimeCantPress)
|
if (time == FlairTimeCantPress)
|
||||||
return String.format(noformats ? "(can't press)" : "§r(--s)§r");
|
return noformats ? "(can't press)" : "§r(--s)§r";
|
||||||
if (time == FlairTimeNonPresser)
|
if (time == FlairTimeNonPresser)
|
||||||
return String.format(noformats ? "(non-presser)" : "§7(--s)§r");
|
return noformats ? "(non-presser)" : "§7(--s)§r";
|
||||||
if (time == FlairTimeNone)
|
if (time == FlairTimeNone)
|
||||||
return "";
|
return "";
|
||||||
return noformats ? String.format("(%ds)", time) : String.format("§%x(%ds)§r", GetFlairColor(), time);
|
return noformats ? String.format("(%ds)", time) : String.format("§%x(%ds)§r", GetFlairColor(), time);
|
||||||
|
@ -130,4 +130,8 @@ public class ChatPlayer extends TBMCPlayerBase {
|
||||||
return 0xc;
|
return 0xc;
|
||||||
return 0xf;
|
return 0xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getF() {
|
||||||
|
return (double) FCount().get() / (double) FDeaths().get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -183,7 +184,7 @@ public class ChatProcessing {
|
||||||
return gson.toJson(json);
|
return gson.toJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TellrawPart createTellraw(CommandSender sender, String message, Player player, ChatPlayer mp,
|
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player, @Nullable ChatPlayer mp,
|
||||||
final String channelidentifier) {
|
final String channelidentifier) {
|
||||||
TellrawPart json = new TellrawPart("");
|
TellrawPart json = new TellrawPart("");
|
||||||
if (mp != null && mp.ChatOnly) {
|
if (mp != null && mp.ChatOnly) {
|
||||||
|
@ -197,10 +198,10 @@ public class ChatProcessing {
|
||||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
||||||
+ "Copy message").setColor(Color.Blue)))
|
+ "Copy message").setColor(Color.Blue)))
|
||||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||||
if (PluginMain.permission.has(player, "tbmc.badge.diamond"))
|
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
||||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Aqua).setBold(true)
|
json.addExtra(new TellrawPart("[P]").setColor(Color.Aqua).setBold(true)
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Diamond Patreon supporter")));
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Diamond Patreon supporter")));
|
||||||
else if (PluginMain.permission.has(player, "tbmc.badge.gold"))
|
else if (PluginMain.permission.has(sender, "tbmc.badge.gold"))
|
||||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Gold).setBold(true)
|
json.addExtra(new TellrawPart("[P]").setColor(Color.Gold).setBold(true)
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
|
||||||
json.addExtra(new TellrawPart(" <"));
|
json.addExtra(new TellrawPart(" <"));
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandClass
|
@CommandClass
|
||||||
public class FTopCommand extends TBMCCommandBase {
|
public class FTopCommand extends TBMCCommandBase {
|
||||||
|
@ -27,16 +33,29 @@ public class FTopCommand extends TBMCCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) {
|
public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) {
|
||||||
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
cached = Arrays.stream(playerdir.listFiles())
|
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
|
||||||
.map(f -> TBMCPlayerBase.getPlayer(
|
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
|
||||||
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
|
.map(f -> TBMCPlayerBase.getPlayer(
|
||||||
.sorted((cp1, cp2) -> Float.compare((float) cp2.FCount().get() / (float) cp2.FDeaths().get(),
|
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
|
||||||
(float) cp1.FCount().get() / (float) cp1.FDeaths().get()))
|
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
|
||||||
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
|
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
|
||||||
lastcache = System.nanoTime();
|
lastcache = System.nanoTime();
|
||||||
}
|
}
|
||||||
Arrays.stream(cached).limit(10);
|
int i;
|
||||||
|
try {
|
||||||
|
i = arg2.length > 0 ? Integer.parseInt(arg2[0]) : 1;
|
||||||
|
if (i < 1)
|
||||||
|
i = 1; //i=1
|
||||||
|
} catch (Exception e) {
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
val ai = new AtomicInteger();
|
||||||
|
arg0.sendMessage("§6---- Top Fs ----");
|
||||||
|
arg0.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
|
||||||
|
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF()))
|
||||||
|
.collect(Collectors.joining("\n")));
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class PlayerListener implements Listener {
|
||||||
mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class);
|
mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class);
|
||||||
else
|
else
|
||||||
mp = null;
|
mp = null;
|
||||||
String cmd = "";
|
String cmd;
|
||||||
if (index == -1) { // Only the command is run
|
if (index == -1) { // Only the command is run
|
||||||
if (!(sender instanceof Player || sender instanceof ConsoleCommandSender))
|
if (!(sender instanceof Player || sender instanceof ConsoleCommandSender))
|
||||||
return false;
|
return false;
|
||||||
|
@ -149,8 +149,7 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
if (PluginMain.permission.has(sender, "tbmc.admin")) {
|
if (PluginMain.permission.has(sender, "tbmc.admin")) {
|
||||||
String s = cmd.substring(2);
|
String s = cmd.substring(2);
|
||||||
Player target = null;
|
Player target = Bukkit.getPlayer(message.substring(index + 1));
|
||||||
target = Bukkit.getPlayer(message.substring(index + 1));
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
sender.sendMessage("§cError: Player not found. (/un" + s + " <player>)");
|
sender.sendMessage("§cError: Player not found. (/un" + s + " <player>)");
|
||||||
return true;
|
return true;
|
||||||
|
@ -260,7 +259,7 @@ public class PlayerListener implements Listener {
|
||||||
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
|
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
|
||||||
if (flair.length() > 0)
|
if (flair.length() > 0)
|
||||||
e.addInfo("/r/TheButton flair: " + flair);
|
e.addInfo("/r/TheButton flair: " + flair);
|
||||||
e.addInfo("Respect: " + (double) cp.FCount().get() / (double) cp.FDeaths().get());
|
e.addInfo("Respect: " + cp.getF());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
|
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue