angadraghav664-a11y

fix bug in this plugin

Kodari AI
KodariJun 13 at 5:12 am 70

Found 7 bugs. Let me read the affected files to fix them all.

Now I have everything I need. Let me fix all 6 bugs:

Now the LightningFruit patches introduce Block usage — need to add the import:

Also need Block import in DarkFruit:

Here’s a summary of all 7 bugs fixed:

#
File
Bug
Fix
1
FlyFruit.java
Missing
Location
import (compile error)
Added
import org.bukkit.Location
2
DarkFruit.java
getTargetBlock()
NPE when looking at air
Guard: check block isn’t null/air before using it
3
LightningFruit.java
(right-click)
getTargetBlock()
NPE when looking at air
Guard: check block + early return with action bar
4
LightningFruit.java
(left-click)
Same NPE on
getTargetBlock()
Same guard pattern
5
FruitUseListener.java
Left-click events not cancelled, allowing vanilla behavior alongside fruit powers
Added
event.setCancelled(true)
for both left-click branches
6
IceFruit.java
applyEffectToNearby(null, ...)
passing hardcoded
null
as player (redundant + risky)
Pass the actual entity as player if it’s a
Player
, otherwise
null
7
SandFruit.java
No-target path reset cooldown to 1 tick, allowing ability spam
Removed the fake 1-tick cooldown reset — ability now correctly doesn’t trigger
angadraghav664-a11y

Compilation Error Missing required files

Kodari can make mistakes. Review important code before using.
Files
src
Code
27 2,503
src/main/java/com/voidfruits/VoidFruits.java
package com.voidfruits;

import com.voidfruits.commands.FruitCommand;
import com.voidfruits.config.ConfigManager;
import com.voidfruits.data.PlayerDataManager;
import com.voidfruits.inventory.gui.GUIListener;
import com.voidfruits.inventory.gui.GUIManager;
import com.voidfruits.listener.FruitUseListener;
import com.voidfruits.listener.PlayerListener;
import com.voidfruits.manager.FruitManager;
import com.voidfruits.placeholder.VoidFruitsExpansion;
import com.voidfruits.util.CooldownManager;
import lombok.Getter;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class VoidFruits extends JavaPlugin {

    public static NamespacedKey FRUIT_TYPE_KEY;

    private ConfigManager configManager;
    private PlayerDataManager playerDataManager;
    private FruitManager fruitManager;
    private CooldownManager cooldownManager;
    private GUIManager guiManager;

    @Override
    public void onEnable() {
        FRUIT_TYPE_KEY = new NamespacedKey(this, "fruit_type");

        saveDefaultConfig();
        configManager = new ConfigManager(this);
        cooldownManager = new CooldownManager();
        playerDataManager = new PlayerDataManager(this);
        fruitManager = new FruitManager(this);
        guiManager = new GUIManager();

        playerDataManager.loadAll();
        fruitManager.init();

        getServer().getPluginManager().registerEvents(new FruitUseListener(this), this);
        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);

        FruitCommand fruitCommand = new FruitCommand(this);
        getCommand("fruit").setExecutor(fruitCommand);
        getCommand("fruit").setTabCompleter(fruitCommand);

        if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new VoidFruitsExpansion(this).register();
            getLogger().info("PlaceholderAPI hooked!");
        }

        getLogger().info("VoidFruits enabled! 15 Devil Fruits awakened.");
    }

    @Override
    public void onDisable() {
        if (playerDataManager != null) playerDataManager.saveAll();
        if (fruitManager != null) fruitManager.cleanup();
        getLogger().info("VoidFruits disabled.");
    }
}