Hotfix & /ftop

This commit is contained in:
Norbi Peti 2018-04-24 21:31:13 +02:00
parent 6202e30522
commit 4a7d7379b0
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 42 additions and 19 deletions

View file

@ -71,9 +71,9 @@ public class ChatPlayer extends TBMCPlayerBase {
public String GetFormattedFlair(boolean noformats) {
int time = FlairTime().get();
if (time == FlairTimeCantPress)
return String.format(noformats ? "(can't press)" : "§r(--s)§r");
return noformats ? "(can't press)" : "§r(--s)§r";
if (time == FlairTimeNonPresser)
return String.format(noformats ? "(non-presser)" : "§7(--s)§r");
return noformats ? "(non-presser)" : "§7(--s)§r";
if (time == FlairTimeNone)
return "";
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 0xf;
}
public double getF() {
return (double) FCount().get() / (double) FDeaths().get();
}
}

View file

@ -25,6 +25,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Objective;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -183,7 +184,7 @@ public class ChatProcessing {
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) {
TellrawPart json = new TellrawPart("");
if (mp != null && mp.ChatOnly) {
@ -197,10 +198,10 @@ public class ChatProcessing {
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
+ "Copy message").setColor(Color.Blue)))
.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)
.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)
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
json.addExtra(new TellrawPart(" <"));

View file

@ -1,14 +1,20 @@
package buttondevteam.chat.commands;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.player.TBMCPlayerBase;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.io.File;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@CommandClass
public class FTopCommand extends TBMCCommandBase {
@ -27,16 +33,29 @@ public class FTopCommand extends TBMCCommandBase {
@Override
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)
cached = Arrays.stream(playerdir.listFiles())
.map(f -> TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
.sorted((cp1, cp2) -> Float.compare((float) cp2.FCount().get() / (float) cp2.FDeaths().get(),
(float) cp1.FCount().get() / (float) cp1.FDeaths().get()))
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
lastcache = System.nanoTime();
}
Arrays.stream(cached).limit(10);
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
.map(f -> TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
lastcache = System.nanoTime();
}
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;
}

View file

@ -78,7 +78,7 @@ public class PlayerListener implements Listener {
mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class);
else
mp = null;
String cmd = "";
String cmd;
if (index == -1) { // Only the command is run
if (!(sender instanceof Player || sender instanceof ConsoleCommandSender))
return false;
@ -149,8 +149,7 @@ public class PlayerListener implements Listener {
}
if (PluginMain.permission.has(sender, "tbmc.admin")) {
String s = cmd.substring(2);
Player target = null;
target = Bukkit.getPlayer(message.substring(index + 1));
Player target = Bukkit.getPlayer(message.substring(index + 1));
if (target == null) {
sender.sendMessage("§cError: Player not found. (/un" + s + " <player>)");
return true;
@ -260,7 +259,7 @@ public class PlayerListener implements Listener {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
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) {
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
}