mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
add page
This commit is contained in:
@@ -31,7 +31,6 @@ import java.util.Optional;
|
|||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
public class LootImpl implements Loot {
|
public class LootImpl implements Loot {
|
||||||
|
|
||||||
private final LootType type;
|
private final LootType type;
|
||||||
private final boolean instantGame;
|
private final boolean instantGame;
|
||||||
private final boolean disableGame;
|
private final boolean disableGame;
|
||||||
|
|||||||
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
package net.momirealms.customfishing.bukkit.command.feature;
|
package net.momirealms.customfishing.bukkit.command.feature;
|
||||||
|
|
||||||
|
import net.kyori.adventure.inventory.Book;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||||
import net.momirealms.customfishing.api.mechanic.context.Context;
|
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||||
@@ -37,6 +40,7 @@ import org.incendo.cloud.Command;
|
|||||||
import org.incendo.cloud.CommandManager;
|
import org.incendo.cloud.CommandManager;
|
||||||
import org.incendo.cloud.context.CommandContext;
|
import org.incendo.cloud.context.CommandContext;
|
||||||
import org.incendo.cloud.context.CommandInput;
|
import org.incendo.cloud.context.CommandInput;
|
||||||
|
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||||
import org.incendo.cloud.parser.standard.StringParser;
|
import org.incendo.cloud.parser.standard.StringParser;
|
||||||
import org.incendo.cloud.suggestion.Suggestion;
|
import org.incendo.cloud.suggestion.Suggestion;
|
||||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||||
@@ -63,6 +67,7 @@ public class DebugLootCommand extends BukkitCommandFeature<CommandSender> {
|
|||||||
return CompletableFuture.completedFuture(Stream.of("lava", "water", "void").map(Suggestion::suggestion).toList());
|
return CompletableFuture.completedFuture(Stream.of("lava", "water", "void").map(Suggestion::suggestion).toList());
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
.optional("page", IntegerParser.integerParser(1))
|
||||||
.handler(context -> {
|
.handler(context -> {
|
||||||
String surrounding = context.get("surrounding");
|
String surrounding = context.get("surrounding");
|
||||||
if (context.sender().getInventory().getItemInMainHand().getType() != Material.FISHING_ROD) {
|
if (context.sender().getInventory().getItemInMainHand().getType() != Material.FISHING_ROD) {
|
||||||
@@ -70,6 +75,7 @@ public class DebugLootCommand extends BukkitCommandFeature<CommandSender> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = context.sender();
|
final Player player = context.sender();
|
||||||
|
int page = (int) context.optional("page").orElse(1) - 1;
|
||||||
|
|
||||||
Context<Player> playerContext = Context.player(player);
|
Context<Player> playerContext = Context.player(player);
|
||||||
FishingGears gears = new FishingGears(playerContext);
|
FishingGears gears = new FishingGears(playerContext);
|
||||||
@@ -112,16 +118,45 @@ public class DebugLootCommand extends BukkitCommandFeature<CommandSender> {
|
|||||||
sum += weight;
|
sum += weight;
|
||||||
}
|
}
|
||||||
LootWithWeight[] lootArray = loots.toArray(new LootWithWeight[0]);
|
LootWithWeight[] lootArray = loots.toArray(new LootWithWeight[0]);
|
||||||
|
int maxPages = (int) Math.ceil((double) lootArray.length / 10) - 1;
|
||||||
|
if (page > maxPages) return;
|
||||||
|
|
||||||
quickSort(lootArray, 0,lootArray.length - 1);
|
quickSort(lootArray, 0,lootArray.length - 1);
|
||||||
Component component = Component.text().build();
|
Component component = Component.empty();
|
||||||
|
List<Component> children = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
for (LootWithWeight loot : lootArray) {
|
for (LootWithWeight loot : lootArray) {
|
||||||
component = component.append(Component.newline())
|
if (i >= page * 10 && i < page * 10 + 10) {
|
||||||
|
children.add(Component.newline()
|
||||||
.append(Component.text(loot.key + ": ").color(NamedTextColor.WHITE))
|
.append(Component.text(loot.key + ": ").color(NamedTextColor.WHITE))
|
||||||
.append(Component.text(String.format("%.4f", loot.weight * 100 / sum) + "% ").color(NamedTextColor.GOLD))
|
.append(Component.text(String.format("%.4f", loot.weight * 100 / sum) + "% ").color(NamedTextColor.GOLD))
|
||||||
.append(Component.text("(" + loot.weight + ")").color(NamedTextColor.GRAY));
|
.append(Component.text("(" + loot.weight + ")").color(NamedTextColor.GRAY)));
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
handleFeedback(context, MessageConstants.COMMAND_DEBUG_LOOT_SUCCESS, component);
|
}
|
||||||
|
handleFeedback(context, MessageConstants.COMMAND_DEBUG_LOOT_SUCCESS, component.children(children));
|
||||||
|
Component previous = Component.text("( <<< )");
|
||||||
|
if (page > 0) {
|
||||||
|
previous = previous.color(NamedTextColor.GREEN).clickEvent(ClickEvent.runCommand(commandConfig.getUsages().get(0) + " " + surrounding + " " + (page)));
|
||||||
|
} else {
|
||||||
|
previous = previous.color(NamedTextColor.GRAY);
|
||||||
|
}
|
||||||
|
Component next = Component.text("( >>> )");
|
||||||
|
if (page < maxPages) {
|
||||||
|
next = next.color(NamedTextColor.GREEN).clickEvent(ClickEvent.runCommand(commandConfig.getUsages().get(0) + " " + surrounding + " " + (page + 2)));
|
||||||
|
} else {
|
||||||
|
next = next.color(NamedTextColor.GRAY);
|
||||||
|
}
|
||||||
|
BukkitCustomFishingPlugin.getInstance().getSenderFactory().wrap(player)
|
||||||
|
.sendMessage(
|
||||||
|
Component.empty().children(List.of(
|
||||||
|
previous,
|
||||||
|
Component.text(" "),
|
||||||
|
Component.text("[" + (page + 1) + "/" + (maxPages + 1) + "]").color(NamedTextColor.AQUA),
|
||||||
|
Component.text(" "),
|
||||||
|
next
|
||||||
|
))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=2.3.10
|
project_version=2.3.11
|
||||||
config_version=38
|
config_version=38
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user