Skip to content

Commit

Permalink
remove ItemConstruct#EMPTY
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Dec 18, 2024
1 parent dfca1e7 commit 7a356b9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.rosewood.rosegarden.utils.StringPlaceholders;
import dev.triumphteam.gui.components.GuiAction;
import dev.triumphteam.gui.guis.BaseGui;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,7 +19,7 @@ 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;
protected ItemConstruct item = ItemConstruct.of(Material.STONE).tooltip(false);

public GuiItem() {
}
Expand Down
28 changes: 4 additions & 24 deletions src/main/java/xyz/oribuin/fishing/fish/Tier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import dev.rosewood.rosegarden.config.CommentedFileConfiguration;
import dev.rosewood.rosegarden.utils.StringPlaceholders;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.stylesheets.LinkStyle;
import xyz.oribuin.fishing.FishingPlugin;
Expand Down Expand Up @@ -43,33 +44,12 @@ public Tier(String name) {
Objects.requireNonNull(name, "Quality name cannot be null.");

this.name = name;
this.baseDisplay = ItemConstruct.EMPTY;
this.baseDisplay = ItemConstruct.of(Material.COD);
this.tierFile = FishUtils.createFile(FishingPlugin.get(), "tiers", name + ".yml");
this.config = CommentedFileConfiguration.loadConfiguration(this.tierFile);
this.fish = new HashMap<>();
}

/**
* Create a new quality name for a fish, Does not create a new file for the quality
*
* @param name The name of the quality
* @param tierFile The file where the relational data is stored
*/
public Tier(String name, File tierFile) {
Objects.requireNonNull(name, "Quality name cannot be null.");

this.name = name;
this.money = 0.0;
this.chance = 0.0;
this.entropy = 0;
this.fishExp = 0;
this.naturalExp = 0.0f;
this.baseDisplay = ItemConstruct.EMPTY;
this.tierFile = tierFile;
this.config = CommentedFileConfiguration.loadConfiguration(this.tierFile);
this.fish = new HashMap<>();
}

/**
* Load the settings from the configuration file
* I would recommend always super calling this method to save any settings that could be implemented
Expand All @@ -81,7 +61,7 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) {
this.money = config.getDouble("money", 0.0);
this.chance = config.getDouble("chance", 0.0);
this.entropy = config.getInt("entropy", 0);
this.baseDisplay = ItemConstruct.EMPTY;
this.baseDisplay = ItemConstruct.of(Material.STONE);
this.baseDisplay.loadSettings(this.pullSection(config, "display-item"));

this.fishExp = config.getInt("fish-exp", 0);
Expand Down Expand Up @@ -191,7 +171,7 @@ public ItemConstruct baseDisplay() {
}

public void baseDisplay(ItemConstruct baseDisplay) {
this.baseDisplay = baseDisplay != null ? baseDisplay : ItemConstruct.EMPTY;
this.baseDisplay = baseDisplay != null ? baseDisplay : ItemConstruct.of(Material.COD);
}

public int fishExp() {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/xyz/oribuin/fishing/listener/FishListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public void onFish(PlayerFishEvent event) {
event.getPlayer().sendMessage("You caught a " + fish.displayName() + "!"); // TODO: Replace with locale message
// locale.sendMessage(event.getPlayer(), "fish-caught", StringPlaceholders.of("fish", fish.displayName()));

ItemStack resultItem = fish.createItemStack();

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

inv.addItem(fish.createItemStack());
inv.addItem(resultItem);
}

Fisher fisher = this.plugin.getManager(DataManager.class).get(event.getPlayer().getUniqueId());
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
public class ItemConstruct implements Configurable {

public static ItemConstruct EMPTY = ItemConstruct.of(Material.STONE); // Empty itemstack

private Material type;
private Integer amount;
private String name;
Expand Down

0 comments on commit 7a356b9

Please sign in to comment.