mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
optimise jalist
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.untamedears.jukealert.commands;
|
||||
|
||||
import static com.untamedears.jukealert.util.JAUtility.findLookingAtOrClosestSnitch;
|
||||
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
@@ -15,6 +12,7 @@ import com.untamedears.jukealert.model.actions.abstr.PlayerAction;
|
||||
import com.untamedears.jukealert.model.actions.abstr.SnitchAction;
|
||||
import com.untamedears.jukealert.model.appender.SnitchLogAppender;
|
||||
import com.untamedears.jukealert.util.JAUtility;
|
||||
import static com.untamedears.jukealert.util.JAUtility.findLookingAtOrClosestSnitch;
|
||||
import com.untamedears.jukealert.util.JukeAlertPermissionHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@@ -23,10 +21,10 @@ import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -183,7 +181,30 @@ public class InfoCommand extends BaseCommand {
|
||||
String playerName,
|
||||
boolean censor) {
|
||||
SnitchLogAppender logAppender = snitch.getAppender(SnitchLogAppender.class);
|
||||
List<LoggableAction> logs = new ArrayList<>(logAppender.getFullLogs());
|
||||
if (snitch.getId() == -1) {
|
||||
displaySnitchLog(player, snitch, logAppender.getFullLogs(), offset, pageLength, actionType, playerName, censor);
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(JukeAlert.getInstance(), () -> {
|
||||
final List<LoggableAction> actions = logAppender.loadLogs();
|
||||
Bukkit.getScheduler().runTask(JukeAlert.getInstance(), () -> {
|
||||
if (!player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
displaySnitchLog(player, snitch, actions, offset, pageLength, actionType, playerName, censor);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void displaySnitchLog(
|
||||
Player player,
|
||||
Snitch snitch,
|
||||
List<LoggableAction> logs,
|
||||
int offset,
|
||||
int pageLength,
|
||||
String actionType,
|
||||
String playerName,
|
||||
boolean censor) {
|
||||
logs = new ArrayList<>(logs);
|
||||
if (playerName != null) {
|
||||
String playerNameLowered = playerName.toLowerCase();
|
||||
List<LoggableAction> logCopy = new LinkedList<>();
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -53,17 +54,8 @@ public class SnitchLogGUI {
|
||||
return this.snitch.hasPermission(this.player.getUniqueId(), permission);
|
||||
}
|
||||
|
||||
private List<IClickable> INTERNAL_constructContent() {
|
||||
if (this.logAppender == null) {
|
||||
final var item = new ItemStack(Material.BARRIER);
|
||||
ItemUtils.setComponentDisplayName(item, Component.text()
|
||||
.decoration(TextDecoration.ITALIC, false)
|
||||
.color(NamedTextColor.RED)
|
||||
.content("This snitch can not create logs")
|
||||
.build());
|
||||
return MoreCollectionUtils.asLazyList(Collections.singletonList(() -> new DecorationStack(item)));
|
||||
}
|
||||
final var actions = this.logAppender.getFullLogs();
|
||||
private @NotNull List<IClickable> INTERNAL_constructContent(
|
||||
final @NotNull List<LoggableAction> actions) {
|
||||
if (actions.isEmpty()) {
|
||||
final var item = new ItemStack(Material.BARRIER);
|
||||
ItemUtils.setComponentDisplayName(item, Component.text()
|
||||
@@ -232,9 +224,35 @@ public class SnitchLogGUI {
|
||||
}
|
||||
|
||||
public void showScreen() {
|
||||
if (this.buttonCache == null) {
|
||||
this.buttonCache = INTERNAL_constructContent();
|
||||
if (this.buttonCache != null) {
|
||||
INTERNAL_showScreenWithContent();
|
||||
return;
|
||||
}
|
||||
if (this.logAppender == null) {
|
||||
final var item = new ItemStack(Material.BARRIER);
|
||||
ItemUtils.setComponentDisplayName(item, Component.text()
|
||||
.decoration(TextDecoration.ITALIC, false)
|
||||
.color(NamedTextColor.RED)
|
||||
.content("This snitch can not create logs")
|
||||
.build());
|
||||
this.buttonCache = MoreCollectionUtils.asLazyList(
|
||||
Collections.singletonList(() -> new DecorationStack(item)));
|
||||
INTERNAL_showScreenWithContent();
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(JukeAlert.getInstance(), () -> {
|
||||
final List<LoggableAction> actions = logAppender.loadLogs();
|
||||
Bukkit.getScheduler().runTask(JukeAlert.getInstance(), () -> {
|
||||
if (!this.player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
this.buttonCache = INTERNAL_constructContent(actions);
|
||||
INTERNAL_showScreenWithContent();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void INTERNAL_showScreenWithContent() {
|
||||
final var view = new MultiPageView(this.player, this.buttonCache,
|
||||
StringUtils.substring(this.snitch.getName(), 0, 32), true);
|
||||
if (this.logAppender != null) {
|
||||
|
||||
@@ -42,13 +42,16 @@ public class SnitchLogAppender extends ConfigurableSnitchAppender<LimitedActionT
|
||||
@NotNull
|
||||
public List<LoggableAction> getFullLogs() {
|
||||
final List<LoggableAction> actions = getSnitch().getId() == -1 ?
|
||||
new ArrayList<>(this.pendingActions.keySet()) :
|
||||
JukeAlert.getInstance().getDAO().loadLogs(
|
||||
getSnitch(), getMaximumActionAge(), this.config.getHardCap());
|
||||
new ArrayList<>(this.pendingActions.keySet()) : loadLogs();
|
||||
actions.sort(ACTION_COMPARATOR);
|
||||
return actions;
|
||||
}
|
||||
|
||||
public List<LoggableAction> loadLogs() {
|
||||
return JukeAlert.getInstance().getDAO().loadLogs(
|
||||
getSnitch(), getMaximumActionAge(), this.config.getHardCap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes <b>ALL</b> logs for this snitch.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user