Skip to content

Commit

Permalink
functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Oct 22, 2024
1 parent e2381f9 commit e7fd777
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 22 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ shadowJar {
relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.persistentdatatypes")
relocate("net.objecthunter.exp4j", "${project.group}.fishing.libs.exp4j")
relocate("dev.triumphteam.gui", "${project.group}.fishing.libs.triumphgui")
relocate("xyz.oribuin.biomeadapter", "${project.group}.fishing.libs.biomeadapter")
}

// Include version replacement
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/xyz/oribuin/fishing/FishingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void enable() {
PluginManager manager = this.getServer().getPluginManager();
manager.registerEvents(new FishListener(this), this);
manager.registerEvents(new PlayerListeners(this), this);
}

@Override
public void reload() {
super.reload();

SkillRegistry.init();
AugmentRegistry.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.oribuin.fishing.FishingPlugin;
import xyz.oribuin.fishing.fish.condition.ConditionRegistry;
import xyz.oribuin.fishing.augment.Augment;
import xyz.oribuin.fishing.augment.AugmentRegistry;
import xyz.oribuin.fishing.fish.Fish;
import xyz.oribuin.fishing.fish.Tier;
import xyz.oribuin.fishing.fish.condition.ConditionRegistry;
import xyz.oribuin.fishing.manager.TierManager;
import xyz.oribuin.fishing.util.FishUtils;

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

Expand Down Expand Up @@ -46,7 +47,7 @@ public FishGenerateEvent(@NotNull Player who, @NotNull ItemStack rod, @NotNull F
this.rod = rod;
this.hook = hook;
this.baseChance = FishUtils.RANDOM.nextDouble(100);
this.generate();
this.chanceIncreases = new ArrayList<>();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package xyz.oribuin.fishing.augment.impl;

import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import dev.rosewood.rosegarden.config.CommentedFileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.api.event.InitialFishCatchEvent;
import xyz.oribuin.fishing.augment.Augment;
import xyz.oribuin.fishing.api.event.FishContext;
import xyz.oribuin.fishing.fish.Fish;

public class AugmentSaturate extends Augment {

Expand All @@ -26,15 +22,15 @@ public AugmentSaturate() {
*/
@Override
public void onInitialCatch(InitialFishCatchEvent event, int level) {
if (event.getPlayer().getSaturation() >= 20.0) return;
if (event.getPlayer().getFoodLevel() >= 20.0) return;

int chanceToTrigger = (int) (this.chancePerLevel * level);
if (Math.random() * 100 > chanceToTrigger) return;

event.getPlayer().setSaturation(20.0f);
event.getPlayer().setFoodLevel(20);
event.getPlayer().sendMessage("You have been fully saturated!");
}


/**
* Load the settings from the configuration file
*
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/xyz/oribuin/fishing/command/FishCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package xyz.oribuin.fishing.command;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.HelpCommand;
import dev.rosewood.rosegarden.command.ReloadCommand;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import xyz.oribuin.fishing.command.impl.ApplyCommand;

public class FishCommand extends BaseRoseCommand {

public FishCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("fish")
.aliases("fishing")
.arguments(this.createArguments())
.playerOnly(true)
.build();
}

private ArgumentsDefinition createArguments() {
return ArgumentsDefinition.builder()
.requiredSub(
new HelpCommand(this.rosePlugin, this),
new ReloadCommand(this.rosePlugin),
new ApplyCommand(this.rosePlugin)
);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package xyz.oribuin.fishing.command.argument;

import dev.rosewood.rosegarden.command.framework.Argument;
import dev.rosewood.rosegarden.command.framework.ArgumentHandler;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.InputIterator;
import dev.rosewood.rosegarden.utils.StringPlaceholders;
import xyz.oribuin.fishing.augment.Augment;
import xyz.oribuin.fishing.augment.AugmentRegistry;

import java.util.List;

public class AugmentArgument extends ArgumentHandler<Augment> {

public AugmentArgument() {
super(Augment.class);
}

@Override
public Augment handle(CommandContext context, Argument argument, InputIterator inputIterator) throws HandledArgumentException {
String input = inputIterator.next();
Augment augment = AugmentRegistry.all().get(input);
if (augment != null) return augment;

throw new HandledArgumentException("argument-handler-augments", StringPlaceholders.of("augment", input));
}

@Override
public List<String> suggest(CommandContext context, Argument argument, String[] args) {
return AugmentRegistry.all().keySet().stream().toList();
}

}
61 changes: 61 additions & 0 deletions src/main/java/xyz/oribuin/fishing/command/impl/ApplyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package xyz.oribuin.fishing.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import xyz.oribuin.fishing.augment.Augment;
import xyz.oribuin.fishing.augment.AugmentRegistry;
import xyz.oribuin.fishing.command.argument.AugmentArgument;

import java.util.HashMap;
import java.util.Map;

public class ApplyCommand extends BaseRoseCommand {

public ApplyCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context, Augment augment, Integer level) {
if (!(context.getSender() instanceof Player player)) return;

ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Material.FISHING_ROD) {
player.sendMessage("You must be holding a fishing rod to apply an augment.");
return;
}

// Get the augment from the argument
Map<Augment, Integer> augments = new HashMap<>(AugmentRegistry.from(item));
augments.put(augment, level);

// Apply the augment to the fishing rod
AugmentRegistry.save(item, augments);

player.sendMessage("Successfully applied the augment to the fishing rod.");
augments.forEach((a, l) -> player.sendMessage("Augment: " + a.name() + " Level: " + l));
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("apply")
.arguments(this.createArguments())
.playerOnly(true)
.build();
}

private ArgumentsDefinition createArguments() {
return ArgumentsDefinition.builder()
.required("augment", new AugmentArgument())
.required("level", ArgumentHandlers.INTEGER)
.build();
}
}
9 changes: 2 additions & 7 deletions src/main/java/xyz/oribuin/fishing/fish/Fish.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -22,7 +21,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Fish implements Configurable {

Expand All @@ -40,10 +38,7 @@ public class Fish implements Configurable {
* @param name The name of the fish
* @param tier The quality of the fish
*/
public Fish(String name, String tier) {
Objects.requireNonNull(name, "Fish name cannot be null.");
Objects.requireNonNull(tier, "Fish tier cannot be null.");

public Fish(@NotNull String name, @NotNull String tier) {
this.name = name;
this.tier = tier;
this.condition = new Condition();
Expand Down Expand Up @@ -96,7 +91,7 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) {
config.set(this.name + ".model-data", this.modelData);

// Conditions for the fish
config.set(this.name + ".biomes", this.condition.biomes().stream().map(Enum::name).toList());
config.set(this.name + ".biomes", this.condition.biomes());
config.set(this.name + ".worlds", this.condition.worlds());
config.set(this.name + ".ice-fishing", this.condition.iceFishing());
config.set(this.name + "boat-fishing", this.condition.boatFishing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public static boolean check(Fish fish, Player player, ItemStack rod, FishHook ho
event.callEvent(); // Call the event

if (event.isCancelled()) continue;
if (!event.getResult()) continue;
return false;
if (!event.getResult()) return false;
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/oribuin/fishing/listener/FishListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void onFish(PlayerFishEvent event) {
newEntropy += fishCatchEvent.getEntropy();

// Tell the player they caught a fish
locale.sendMessage(event.getPlayer(), "fish-caught", StringPlaceholders.of("fish", fish.displayName()));
event.getPlayer().sendMessage("You caught a " + fish.displayName() + "!"); // TODO: Replace with locale message
// locale.sendMessage(event.getPlayer(), "fish-caught", StringPlaceholders.of("fish", fish.displayName()));

// Give the fish to the player
PlayerInventory inv = event.getPlayer().getInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.manager.AbstractCommandManager;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.command.FishCommand;

import java.util.List;
import java.util.function.Function;
Expand All @@ -16,7 +17,7 @@ public CommandManager(RosePlugin rosePlugin) {

@Override
public @NotNull List<Function<RosePlugin, BaseRoseCommand>> getRootCommands() {
return List.of();
return List.of(FishCommand::new);
}

}
3 changes: 3 additions & 0 deletions src/main/java/xyz/oribuin/fishing/manager/FishManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ public List<Fish> tryCatch(Player player, ItemStack rod, FishHook hook) {
private Fish generateFish(Player player, ItemStack rod, FishHook hook) {
FishGenerateEvent event = new FishGenerateEvent(player, rod, hook);
Bukkit.getPluginManager().callEvent(event);

event.generate();
if (event.isCancelled()) return null;
if (event.getFish() == null) return null;

return event.getFish();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/oribuin/fishing/manager/TierManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void reload() {
/**
* Get the quality of fish dependent on the chance provided, filters through all chances
* sorted for rarest -> common, seeing if chance <= tier chance. When no tier is selected it will return null.
* Usually, a null tier means a player wont get a custom fish
* Usually, a null tier means a player won't get a custom fish
*
* @param chance The chance of obtaining the fish
*
Expand Down

0 comments on commit e7fd777

Please sign in to comment.