package com.archivesmc.painter.integrations;

import com.archivesmc.painter.Painter;
import com.worldcretornica.plotme_core.Plot;
import com.worldcretornica.plotme_core.PlotId;
import com.worldcretornica.plotme_core.PlotMeCoreManager;
import com.worldcretornica.plotme_core.api.ILocation;
import com.worldcretornica.plotme_core.bukkit.api.BukkitLocation;
import com.worldcretornica.plotme_core.bukkit.api.BukkitWorld;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

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

public class PlotMeIntegration implements Integration {
    private final Painter plugin;

    public PlotMeIntegration(final Painter plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean canEdit(final Block block, final Player player) {
        // This API is pretty silly
        PlotMeCoreManager manager = PlotMeCoreManager.getInstance();
        ILocation location = new BukkitLocation(block.getLocation());
        PlotId plotId = manager.getPlotId(location);

        if (plotId == null) {
            return false; // For now
        }

        Plot plot = manager.getPlotById(plotId, new BukkitWorld(block.getWorld()));

        return plot != null && plot.isAllowed(player.getUniqueId());

    }

    @Override
    public String getPluginName() {
        return "PlotMe";
    }

    @Override
    public boolean setUp() {
        Plugin plotMePlugin = this.plugin.getServer().getPluginManager().getPlugin("PlotMe");

        return plotMePlugin != null && plotMePlugin.isEnabled();

    }

    @Override
    public void notifyNotAllowed(final Block block, final Player player) {
        // This API is pretty silly
        PlotMeCoreManager manager = PlotMeCoreManager.getInstance();
        ILocation location = new BukkitLocation(block.getLocation());
        Plot plot = manager.getPlotById(manager.getPlotId(location), new BukkitWorld(block.getWorld()));

        Map<String, String> args = new HashMap<>();

        args.put("name", plot.getPlotName());
        args.put("owner", plot.getOwner());

        this.plugin.sendMessage(player, "plotme_not_allowed", args);
    }

    @Override
    public void blockReplaced(final Block block, final Player player) {
        // Honey badger don't care
    }
}

@@ -274,32 +274,95 @@
 .api.ILocation;%0A
+import com.worldcretornica.plotme_core.bukkit.api.BukkitBlock;%0A
 import com.world
@@ -403,32 +403,32 @@
 BukkitLocation;%0A
-
 import com.world
@@ -982,32 +982,305 @@
 .getInstance();%0A
+%0A        if (! manager.isPlotWorld(new BukkitBlock(block))) %7B%0A            // Not a plot world%0A            return true;%0A        %7D%0A%0A        if (player.hasPermission(%22plotme.admin.buildanywhere%22)) %7B%0A            // Allowed to build anywhere%0A            return true;%0A        %7D%0A%0A
         ILocatio
@@ -1413,24 +1413,51 @@
  == null) %7B%0A
+            // On the road%0A
             
@@ -1473,19 +1473,8 @@
 lse;
- // For now
 %0A   
@@ -1558,32 +1558,60 @@
 .getWorld()));%0A%0A
+        // On the road also%0A
         return p

Update PlotMe integration