Skip to content

Commit

Permalink
1.21 + Menu Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Nov 22, 2024
1 parent 8a24379 commit a38678f
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 33 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ plugins {

group = 'xyz.oribuin'
version = '1.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
disableAutoTargetJvm()
}


compileJava {
options.compilerArgs += ['-parameters']
options.fork = true
Expand Down Expand Up @@ -54,7 +56,7 @@ shadowJar {
archiveClassifier.set(null)

relocate("dev.rosewood.rosegarden", "${project.group}.fishing.libs.rosegarden")
relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.persistentdatatypes")
relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.pdt")
relocate("net.objecthunter.exp4j", "${project.group}.fishing.libs.exp4j")
relocate("dev.triumphteam.gui", "${project.group}.fishing.libs.triumphgui")
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs='-Dfile.encoding=UTF-8'

# API Versions
spigotVersion=1.20.4
spigotVersion=1.21.1
gardenVersion=1.3.1
vaultVersion=1.7
authLibVersion=1.5.21
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/xyz/oribuin/fishing/FishingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import xyz.oribuin.fishing.augment.AugmentRegistry;
import xyz.oribuin.fishing.listener.FishListener;
import xyz.oribuin.fishing.listener.PlayerListeners;
import xyz.oribuin.fishing.manager.CommandManager;
import xyz.oribuin.fishing.manager.ConfigurationManager;
import xyz.oribuin.fishing.manager.DataManager;
import xyz.oribuin.fishing.manager.FishManager;
import xyz.oribuin.fishing.manager.LocaleManager;
import xyz.oribuin.fishing.manager.MenuManager;
import xyz.oribuin.fishing.manager.TierManager;
import xyz.oribuin.fishing.manager.TotemManager;
import xyz.oribuin.fishing.manager.base.CommandManager;
import xyz.oribuin.fishing.manager.base.ConfigurationManager;
import xyz.oribuin.fishing.manager.base.DataManager;
import xyz.oribuin.fishing.manager.base.LocaleManager;
import xyz.oribuin.fishing.skill.SkillRegistry;

import java.util.List;
Expand Down Expand Up @@ -58,7 +60,12 @@ public void disable() {

@Override
protected @NotNull List<Class<? extends Manager>> getManagerLoadPriority() {
return List.of(TierManager.class, FishManager.class);
return List.of(
TierManager.class,
FishManager.class,
MenuManager.class,
TotemManager.class
);
}

}
22 changes: 20 additions & 2 deletions src/main/java/xyz/oribuin/fishing/api/config/Configurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.rosewood.rosegarden.config.CommentedFileConfiguration;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.oribuin.fishing.FishingPlugin;

import java.io.File;
Expand Down Expand Up @@ -54,8 +55,10 @@ default List<String> comments() {
*
* @return The path
*/
@NotNull
Path configPath();
@Nullable
default Path configPath() {
return null;
}

/**
* The parent folder of the configuration file, this should be the starting point for every config path
Expand All @@ -72,6 +75,7 @@ default File parentFolder() {
*/
default void reload() {
FishingPlugin plugin = FishingPlugin.get();
if (this.configPath() == null) return;
File targetFile = new File(this.parentFolder(), this.configPath().toString());

try {
Expand Down Expand Up @@ -118,4 +122,18 @@ private void createFile(File target) throws IOException {
target.createNewFile();
}

/**
* Pull a section from the configuration file and save the settings
*
* @param base The base section to pull from
* @param name The name of the section
*/
@NotNull
default CommentedConfigurationSection pullSection(CommentedConfigurationSection base, String name) {
CommentedConfigurationSection section = base.getConfigurationSection(name);
if (section == null) section = base.createSection(name);

return section;
}

}
3 changes: 0 additions & 3 deletions src/main/java/xyz/oribuin/fishing/api/event/FishContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@
* @param level The level of the augment/skill/upgrade that was used
*/
public record FishContext(Player player, ItemStack itemStack, FishHook hook, int level) {

// Unused

}
147 changes: 147 additions & 0 deletions src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package xyz.oribuin.fishing.api.gui;

import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import dev.triumphteam.gui.components.GuiAction;
import dev.triumphteam.gui.guis.BaseGui;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.api.config.Configurable;
import xyz.oribuin.fishing.util.ItemConstruct;

import java.util.ArrayList;
import java.util.List;

public class GuiItem implements Configurable {

protected boolean enabled = true;
protected String name = "item";
protected List<Integer> slot = List.of(0);
protected ItemConstruct item = ItemConstruct.EMPTY;

/**
* Place the item in the specified slot in the GUI
*
* @param gui The GUI to place the item in
* @param function The function to run when the item is clicked
*/
public void place(BaseGui gui, GuiAction<InventoryClickEvent> function) {
if (gui == null) return;
if (!this.enabled) return;

int guiSize = gui.getRows() * 9;
this.slot.forEach(x -> {
if (x < 0 || x >= guiSize) return;

ItemStack item = this.item.build();
if (item == null) return;

gui.setItem(slot, new dev.triumphteam.gui.guis.GuiItem(item, function));
});
}

/**
* Load the settings from the configuration file
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to load
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
this.enabled = config.getBoolean("enabled", true);
this.name = config.getString("name");

int slot = config.getInt("slot", -1);
if (slot > 0) this.slot = List.of(slot);

List<String> slots = config.getStringList("slots");
if (!slots.isEmpty()) this.slot = this.parseSlotList(slots);

CommentedConfigurationSection item = config.getConfigurationSection("item");
if (item != null) {
this.item = ItemConstruct.deserialize(item);
}

System.out.println("Loaded item: " + this.name);
}

/**
* Save the configuration file for the configurable class
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to save
*/
@Override
public void saveSettings(@NotNull CommentedConfigurationSection config) {
config.set("enabled", this.enabled);
config.set("name", this.name);

if (this.slot.size() == 1) config.set("slot", this.slot.get(0));
else config.set("slots", this.slot.stream().map(String::valueOf).toList());

CommentedConfigurationSection item = config.getConfigurationSection("item");
if (item == null) item = config.createSection("item");

this.item.serialize(item);
}

/**
* Parse the slots from the configuration file to a list of integers
*
* @param lines The lines to parse
*
* @return The list of integers
*/
private List<Integer> parseSlotList(List<String> lines) {
List<Integer> slots = new ArrayList<>();
for (String line : lines) {
slots.addAll(this.parseSlots(line));
}
return slots;
}

/**
* Parse the slots from the configuration file to a list of integers
*
* @param line The line to parse
*
* @return The list of integers
*/
private List<Integer> parseSlots(String line) {
try {
String[] split = line.split("-");
if (split.length == 2) {
int start = Integer.parseInt(split[0]);
int end = Integer.parseInt(split[1]);

List<Integer> results = new ArrayList<>();
for (int i = start; i <= end; i++) {
results.add(i);
}

return results;
}

return List.of(Integer.parseInt(line));
} catch (NumberFormatException e) {
return List.of(0);
}
}

public boolean enabled() {
return enabled;
}

public String name() {
return name;
}

public List<Integer> slot() {
return slot;
}

public ItemConstruct item() {
return item;
}

}
Loading

0 comments on commit a38678f

Please sign in to comment.