Skip to content

Commit 01f3895

Browse files
author
Oribuin
committed
start fish codex
Took 6 minutes
1 parent 668a440 commit 01f3895

11 files changed

Lines changed: 250 additions & 11 deletions

File tree

build.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ version = "1.0"
1212
java {
1313
sourceCompatibility = JavaVersion.VERSION_17
1414
targetCompatibility = JavaVersion.VERSION_17
15-
15+
1616
disableAutoTargetJvm()
1717
toolchain {
1818
languageVersion.set(JavaLanguageVersion.of(21))
@@ -34,7 +34,7 @@ repositories {
3434
}
3535

3636
dependencies {
37-
api("dev.rosewood:rosegarden:1.4.4")
37+
api("dev.rosewood:rosegarden:1.4.7-SNAPSHOT")
3838
api("dev.triumphteam:triumph-gui:3.1.10") { // https://mf.mattstudios.me/triumph-gui/introduction
3939
exclude(group = "com.google.code.gson", module = "gson") // Remove GSON, Already included in spigot api
4040
exclude(group = "net.kyori", module = "*") // Remove kyori
@@ -53,7 +53,7 @@ tasks {
5353
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD").start()
5454
val output = ByteArrayOutputStream()
5555
process.inputStream.copyTo(output)
56-
56+
5757
output.toString().trim()
5858
}
5959

@@ -67,7 +67,7 @@ tasks {
6767
// add commit hash to the jar name
6868
this.archiveClassifier.set("")
6969
this.archiveVersion.set(commitHash)
70-
70+
7171
this.relocate("dev.rosewood.rosegarden", "${project.group}.fishing.libs.rosegarden")
7272
this.relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.pdt")
7373
this.relocate("net.objecthunter.exp4j", "${project.group}.fishing.libs.exp4j")
@@ -79,7 +79,9 @@ tasks {
7979
}
8080

8181
processResources {
82-
this.expand("version" to project.version, "commit" to commitHash)
82+
this.from("src/main/java/resources/plugin.yml") { // todo: fix
83+
this.expand("version" to project.version, "commit" to commitHash)
84+
}
8385
}
8486

8587
javadoc {
@@ -133,7 +135,7 @@ tasks {
133135
}
134136

135137
build {
136-
this.dependsOn(javadoc)
138+
// this.dependsOn(javadoc)
137139
this.dependsOn(shadowJar)
138140
}
139141
}

src/main/java/dev/oribuin/fishing/command/FishCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package dev.oribuin.fishing.command;
22

33
import dev.oribuin.fishing.command.impl.ApplyCommand;
4+
import dev.oribuin.fishing.command.impl.CodexCommand;
45
import dev.oribuin.fishing.command.impl.MenuCommand;
5-
import dev.oribuin.fishing.command.impl.admin.GiveCommand;
6+
import dev.oribuin.fishing.command.impl.GiveCommand;
67
import dev.rosewood.rosegarden.RosePlugin;
78
import dev.rosewood.rosegarden.command.HelpCommand;
89
import dev.rosewood.rosegarden.command.ReloadCommand;
@@ -41,7 +42,8 @@ private ArgumentsDefinition createArguments() {
4142
new ReloadCommand(this.rosePlugin),
4243
new ApplyCommand(this.rosePlugin),
4344
new MenuCommand(this.rosePlugin),
44-
new GiveCommand(this.rosePlugin)
45+
new GiveCommand(this.rosePlugin),
46+
new CodexCommand(this.rosePlugin)
4547
);
4648
}
4749

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dev.oribuin.fishing.command.impl;
2+
3+
import dev.oribuin.fishing.command.impl.codex.CodexFishCommand;
4+
import dev.rosewood.rosegarden.RosePlugin;
5+
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
6+
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
7+
import dev.rosewood.rosegarden.command.framework.CommandInfo;
8+
9+
public class CodexCommand extends BaseRoseCommand {
10+
11+
public CodexCommand(RosePlugin rosePlugin) {
12+
super(rosePlugin);
13+
}
14+
15+
/**
16+
* @return The command information
17+
*/
18+
@Override
19+
protected CommandInfo createCommandInfo() {
20+
return CommandInfo.builder("codex")
21+
.descriptionKey("command-codex-description")
22+
.permission("fishing.codex")
23+
.arguments(this.createArguments())
24+
.build();
25+
}
26+
27+
private ArgumentsDefinition createArguments() {
28+
return ArgumentsDefinition.builder().requiredSub(
29+
new CodexFishCommand(this.rosePlugin)
30+
);
31+
}
32+
}

src/main/java/dev/oribuin/fishing/command/impl/admin/GiveCommand.java renamed to src/main/java/dev/oribuin/fishing/command/impl/GiveCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.oribuin.fishing.command.impl.admin;
1+
package dev.oribuin.fishing.command.impl;
22

33
import dev.oribuin.fishing.command.impl.admin.give.GiveAugmentCommand;
44
import dev.oribuin.fishing.command.impl.admin.give.GiveFishCommand;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.oribuin.fishing.command.impl.codex;
2+
3+
import dev.oribuin.fishing.command.argument.TierArgument;
4+
import dev.oribuin.fishing.gui.codex.impl.FishCodexMenu;
5+
import dev.oribuin.fishing.model.fish.Tier;
6+
import dev.rosewood.rosegarden.RosePlugin;
7+
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
8+
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
9+
import dev.rosewood.rosegarden.command.framework.CommandContext;
10+
import dev.rosewood.rosegarden.command.framework.CommandInfo;
11+
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
12+
import org.bukkit.entity.Player;
13+
14+
public class CodexFishCommand extends BaseRoseCommand {
15+
16+
public CodexFishCommand(RosePlugin rosePlugin) {
17+
super(rosePlugin);
18+
}
19+
20+
@RoseExecutable
21+
public void execute(CommandContext context, Tier tier) {
22+
Player sender = (Player) context.getSender(); // todo: allow /fishing codex fish <tier> [player]
23+
FishCodexMenu.open(sender, tier);
24+
}
25+
26+
/**
27+
* @return The command information
28+
*/
29+
@Override
30+
protected CommandInfo createCommandInfo() {
31+
return CommandInfo.builder("fish")
32+
.arguments(ArgumentsDefinition.of("tier", new TierArgument()))
33+
.descriptionKey("command-codex-fish")
34+
.playerOnly(true) // todo: allow /fishing codex fish <tier> [player]
35+
.permission("fishing.codex.fish")
36+
.build();
37+
}
38+
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dev.oribuin.fishing.gui.codex;
2+
3+
import dev.oribuin.fishing.FishingPlugin;
4+
import dev.oribuin.fishing.api.gui.PluginMenu;
5+
import dev.triumphteam.gui.guis.PaginatedGui;
6+
import org.bukkit.entity.Player;
7+
8+
import java.util.List;
9+
import java.util.function.Predicate;
10+
11+
public abstract class BasicCodexMenu<T> extends PluginMenu<PaginatedGui> {
12+
13+
/**
14+
* Creates a new plugin menu instance, with the specified name
15+
*
16+
* @param plugin The plugin instance
17+
* @param name The name of the menu, will be also function as the menu path
18+
*/
19+
public BasicCodexMenu(FishingPlugin plugin, String name) {
20+
super(plugin, name);
21+
}
22+
23+
/**
24+
* Get all the content that is going to be displayed in the codex
25+
*
26+
* @param player The player to get the content for
27+
* @param condition The condition required to display the content
28+
*
29+
* @return The content to display in the menu
30+
*/
31+
public abstract List<T> getContent(Player player, Predicate<T> condition);
32+
33+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package dev.oribuin.fishing.gui.codex.impl;
2+
3+
import dev.oribuin.fishing.FishingPlugin;
4+
import dev.oribuin.fishing.gui.codex.BasicCodexMenu;
5+
import dev.oribuin.fishing.gui.totem.TotemMainMenu;
6+
import dev.oribuin.fishing.manager.MenuManager;
7+
import dev.oribuin.fishing.manager.TierManager;
8+
import dev.oribuin.fishing.model.fish.Fish;
9+
import dev.oribuin.fishing.model.fish.Tier;
10+
import dev.oribuin.fishing.model.totem.Totem;
11+
import dev.triumphteam.gui.guis.Gui;
12+
import dev.triumphteam.gui.guis.GuiItem;
13+
import dev.triumphteam.gui.guis.PaginatedGui;
14+
import org.bukkit.entity.Player;
15+
import org.bukkit.inventory.ItemStack;
16+
17+
import javax.naming.Context;
18+
import java.util.List;
19+
import java.util.function.Predicate;
20+
21+
public class FishCodexMenu extends BasicCodexMenu<Fish> {
22+
23+
/**
24+
* Creates a new plugin menu instance, with the specified name
25+
*
26+
* @param plugin The plugin instance
27+
*/
28+
public FishCodexMenu(FishingPlugin plugin) {
29+
super(plugin, "codex/fish");
30+
}
31+
32+
/**
33+
* Open the GUI for the specified player
34+
*
35+
* @param player The player to open the GUI for
36+
* @param tier The tier to open the GUI for
37+
*/
38+
public static void open(Player player, Tier tier) {
39+
FishCodexMenu menu = MenuManager.from(FishCodexMenu.class);
40+
if (menu == null) return;
41+
42+
PaginatedGui gui = menu.createPaginated();
43+
menu.placeExtras(tier.placeholders());
44+
menu.placeItem("forward", x -> gui.next());
45+
menu.placeItem("back", x -> gui.previous());
46+
47+
List<Fish> content = menu.getContent(player, fish -> fish.tierName().equalsIgnoreCase(tier.name()));
48+
49+
// Add all the fish to the GUI
50+
content.forEach(fish -> {
51+
gui.addItem(new GuiItem(fish.createItemStack()));
52+
});
53+
54+
gui.open(player);
55+
}
56+
57+
/**
58+
* Get all the content that is going to be displayed in the codex
59+
*
60+
* @param player The player to get the content for
61+
* @param condition The condition required to display the content
62+
*
63+
* @return The content to display in the menu
64+
*/
65+
@Override
66+
public List<Fish> getContent(Player player, Predicate<Fish> condition) {
67+
return this.plugin.getManager(TierManager.class)
68+
.fish()
69+
.stream()
70+
.filter(condition)
71+
.toList();
72+
}
73+
74+
}

src/main/java/dev/oribuin/fishing/manager/MenuManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dev.oribuin.fishing.FishingPlugin;
44
import dev.oribuin.fishing.api.gui.PluginMenu;
5+
import dev.oribuin.fishing.gui.codex.BasicCodexMenu;
6+
import dev.oribuin.fishing.gui.codex.impl.FishCodexMenu;
57
import dev.oribuin.fishing.gui.totem.TotemMainMenu;
68
import dev.rosewood.rosegarden.RosePlugin;
79
import dev.rosewood.rosegarden.manager.Manager;
@@ -23,6 +25,7 @@ public void reload() {
2325

2426
// Register the menus
2527
menus.put(TotemMainMenu.class, new TotemMainMenu(FishingPlugin.get()));
28+
menus.put(FishCodexMenu.class, new FishCodexMenu(FishingPlugin.get()));
2629

2730
// Load all the menus
2831
menus.values().forEach(PluginMenu::reload);

src/main/java/dev/oribuin/fishing/model/condition/impl/TimeCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public boolean check(Fish fish, Player player, ItemStack rod, FishHook hook) {
7979
@Override
8080
public StringPlaceholders placeholders() {
8181
return StringPlaceholders.builder()
82-
.add("time", StringUtils.capitalize(this.time.name()))
82+
.add("time", StringUtils.capitalize(this.time.name().toLowerCase().replace("_", " ")))
8383
.add("use_system_time", this.systemTime)
8484
.build();
8585
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Fishing Plugin Menu [totem - main_menu] - Control panel for a totem
3+
#
4+
# title - The title of the gui
5+
# rows - The amount of rows the gui has
6+
# items - all the items that have assigned functionality
7+
# extra-items - additional decorative items, these do nothing
8+
title: Fish Codex
9+
rows: 5
10+
items:
11+
forward:
12+
enabled: true
13+
slot: 5
14+
display-item:
15+
type: ARROW
16+
name: '&f[&#4f73d6&lNext Page&f]'
17+
lore:
18+
- ''
19+
- '&7Click here to go to the next page'
20+
additional-tooltip: false
21+
back:
22+
enabled: true
23+
slot: 3
24+
display-item:
25+
type: ARROW
26+
name: '&f[&#4f73d6&lPrevious Page&f]'
27+
lore:
28+
- ''
29+
- '&7Click here to go to the previous page'
30+
additional-tooltip: false
31+
32+
# Decorative items that do nothing
33+
extra-items:
34+
'border':
35+
enabled: true
36+
slots:
37+
- '0-9'
38+
- '35-44'
39+
- '17-18'
40+
- '26-27'
41+
display-item:
42+
type: BLACK_STAINED_GLASS_PANE
43+
tooltip: false
44+
menu-information:
45+
enabled: true
46+
slot: 4
47+
display-item:
48+
type: OAK_HANGING_SIGN
49+
name: '&f[&#4f73d6&lFish Codex&f]'
50+
lore:
51+
- ''
52+
- '&7Here are all the fish you can catch'
53+
glowing: true
54+
additional-tooltip: false

0 commit comments

Comments
 (0)