package com.trafalcraft.anti_redstone_clock.util.plotSquared;


import org.bukkit.World;
import org.bukkit.Location;
import com.plotsquared.core.PlotAPI;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.bukkit.util.BukkitUtil;

public class PlotSquared_7 implements IPlotSquared {
    private PlotAPI api;

    @Override
    public void init() {
        api = new PlotAPI();
    }

    @Override
    public boolean isAllowedPlot(Location location) {
        if (api == null) api = new PlotAPI();
        if (location == null || location.getWorld() == null) return false;
        com.plotsquared.core.location.Location plotLoc = BukkitUtil.adapt(location);
        if (plotLoc == null) return false;
        com.plotsquared.core.plot.PlotArea area = plotLoc.getPlotArea();
        if (area == null) return false;
        com.plotsquared.core.plot.Plot plot = area.getPlot(plotLoc);
        if (plot == null) return false;
        // Prüfe das redstone-Setting per Reflection
        try {
            if (plot.getSettings() != null) {
                Object settings = plot.getSettings();
                java.lang.reflect.Method m = settings.getClass().getMethod("isRedstone");
                Object result = m.invoke(settings);
                if (result instanceof Boolean && !((Boolean) result)) {
                    return false; // Redstone ist auf diesem Plot verboten
                }
            }
        } catch (Exception e) {
            // Wenn Setting nicht abfragbar, Redstone erlauben
        }
        return true;
    }

    @Override
    public String getVersion() {
        return "7.x";
    }
}
