Skip to content

Commit

Permalink
loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Oct 2, 2024
1 parent 71f23ca commit 90a88fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
13 changes: 2 additions & 11 deletions src/main/java/xyz/oribuin/fishing/fish/Fish.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,11 @@ public Fish(String name, String tier) {
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
String name = config.getString(this.name + "name");
String tier = config.getString(this.name + "tier");

// Make sure the name is not null
if (this.name == null || this.tier == null) {
FishingPlugin.get().getLogger().warning("'name' is null for fish");
return;
}

// Load additional values from the config
Fish fish = new Fish(name, tier);
System.out.println("Loading fish: " + name);

// Catch Conditions
this.displayName = config.getString("display-name", name);
this.displayName = config.getString("display-name", StringUtils.capitalize(this.name));
this.description = config.getStringList("description");
this.modelData = config.getInt("model-data", -1);

Expand Down
32 changes: 23 additions & 9 deletions src/main/java/xyz/oribuin/fishing/listener/FishListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import xyz.oribuin.fishing.FishingPlugin;
import xyz.oribuin.fishing.fish.Fish;
import xyz.oribuin.fishing.fish.Tier;
import xyz.oribuin.fishing.manager.DataManager;
import xyz.oribuin.fishing.manager.FishManager;
import xyz.oribuin.fishing.manager.LocaleManager;
import xyz.oribuin.fishing.storage.Fisher;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -43,29 +45,41 @@ public void onFish(PlayerFishEvent event) {

// Add the fish into the player inventory
double baseExpGained = event.getExpToDrop();
AtomicReference<Double> newExp = new AtomicReference<>(0.0);
caught.forEach(fish -> {
if (fish == null) return; // shouldn't happen but just in case
double naturalExp = 0.0;
double newFishExp = 0.0;
int newEntropy = 0;

for (Fish fish : caught) {
if (fish == null) continue;

Tier tier = fish.tier();
if (tier == null) return; // shouldn't happen but just in case
if (fish.tier() == null) continue;

naturalExp += baseExpGained * tier.naturalExp();
newFishExp += tier.fishExp();
newEntropy += tier.entropy();

// Tell the player they caught a fish
locale.sendMessage(event.getPlayer(), "fish-caught", StringPlaceholders.of("fish", fish.displayName()));

// gIve the fish to the player
// Give the fish to the player
PlayerInventory inv = event.getPlayer().getInventory();
if (inv.firstEmpty() == -1) {
event.getPlayer().getWorld().dropItem(event.getPlayer().getLocation(), fish.createItemStack());
return;
continue;
}

inv.addItem(fish.createItemStack());
newExp.set(newExp.get() + (baseExpGained * tier.naturalExp()));
});
}

// Apply more exp to the player
event.setExpToDrop(newExp.get().intValue());
event.setExpToDrop((int) naturalExp);

// TODO: Give the player entropy
// TODO: Give the player statistics

// Fisher fisher = this.plugin.getManager(DataManager.class).get

}

}
1 change: 0 additions & 1 deletion src/main/java/xyz/oribuin/fishing/manager/FishManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public List<Fish> tryCatch(Player player, ItemStack rod, FishHook hook) {
List<Fish> result = new ArrayList<>();
Map<Augment, Integer> augments = AugmentManager.getAugments(rod);

// TODO: Check for augments on the fishing rod
InitialFishCatchEvent event = new InitialFishCatchEvent(player, rod, hook);
event.callEvent();

Expand Down

0 comments on commit 90a88fd

Please sign in to comment.