Skip to content

Commit

Permalink
Added PlotSquared clear event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mwthorn committed Mar 9, 2018
1 parent 78dbf47 commit 7a11d1c
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
@@ -0,0 +1,111 @@
package com.denizenscript.depenizen.bukkit.events.plotsquared;

import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.plotsquared.bukkit.events.PlotClearEvent;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

// <--[event]
// @Events
// plotsquared plot clear plotsquaredplot
// plotsquared plot clears plotsquaredplot
// plotsquared plot clear <dplotsquaredplot>
// plotsquared plot clears <dplotsquaredplot>
//
// @Regex ^on plotsquared plot [^\s]+ clears( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Cancellable true
//
// @Triggers when a plot is cleared.
//
// @Context
// <context.plot> returns the plot that is cleared.
//
// @Plugin DepenizenBukkit, PlotSquared
//
// -->

public class PlotClearScriptEvent extends BukkitScriptEvent implements Listener {

public PlotClearScriptEvent() {
instance = this;
}

public static PlotClearScriptEvent instance;
public PlotClearEvent event;
public dPlotSquaredPlot plot;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
return lower.startsWith("plotsquared plot clear") || lower.startsWith("plotsquared plot clears");
}

@Override
public boolean matches(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
String plotName = CoreUtilities.getXthArg(3, lower);
if (plotName.equals("plotsquaredplot")) {
return true;
}
dPlotSquaredPlot dplot = dPlotSquaredPlot.valueOf(plotName);
return dplot != null && dplot.equals(plot);
}

@Override
public String getName() {
return "PlotClearEvent";
}

@Override
public void init() {
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance());
}

@Override
public void destroy() {
PlotClearEvent.getHandlerList().unregister(this);
}

@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
String lower = CoreUtilities.toLowerCase(determination);

if (aH.matchesInteger(lower)) {
return true;
}
return super.applyDetermination(container, determination);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(null, null);
}

@Override
public dObject getContext(String name) {
if (name.equals("plot")) {
return plot;
}
return super.getContext(name);
}

@EventHandler
public void onPlotClear(PlotClearEvent event) {
plot = new dPlotSquaredPlot(event.getPlot());

cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
}
@@ -1,6 +1,7 @@
package com.denizenscript.depenizen.bukkit.objects;

import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
Expand Down Expand Up @@ -237,6 +238,24 @@ public String getAttribute(Attribute attribute) {
return new dCuboid(l1, l2).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plotsquaredplot.all_cuboids>
// @returns dList(dCuboid)
// @description
// Returns all the plot's cuboids in a list. Useful for merged plots.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("all_cuboids")) {
dList cuboids = new dList();
dWorld world = dWorld.valueOf(plot.getArea().worldname);
for (RegionWrapper region : plot.getRegions()) {
Location l1 = new Location(world.getWorld(), region.minX, region.minY, region.minZ);
Location l2 = new Location(world.getWorld(), region.maxX, region.maxY, region.maxZ);
cuboids.add(new dCuboid(l1, l2).identify());
}
return cuboids.getAttribute(attribute.fulfill(1));
}

return new Element(identify()).getAttribute(attribute);

}
Expand Down
Expand Up @@ -3,6 +3,7 @@

import com.denizenscript.depenizen.bukkit.events.plotsquared.PlayerEntersPlotScriptEvent;
import com.denizenscript.depenizen.bukkit.events.plotsquared.PlayerLeavePlotScriptEvent;
import com.denizenscript.depenizen.bukkit.events.plotsquared.PlotClearScriptEvent;
import com.denizenscript.depenizen.bukkit.extensions.plotsquared.PlotSquaredElementExtension;
import com.denizenscript.depenizen.bukkit.extensions.plotsquared.PlotSquaredLocationExtension;
import com.denizenscript.depenizen.bukkit.extensions.plotsquared.PlotSquaredPlayerExtension;
Expand All @@ -17,6 +18,7 @@ public class PlotSquaredSupport extends Support {
public PlotSquaredSupport() {
registerScriptEvents(new PlayerEntersPlotScriptEvent());
registerScriptEvents(new PlayerLeavePlotScriptEvent());
registerScriptEvents(new PlotClearScriptEvent());
registerObjects(dPlotSquaredPlot.class);
registerProperty(PlotSquaredPlayerExtension.class, dPlayer.class);
registerProperty(PlotSquaredElementExtension.class, Element.class);
Expand Down

0 comments on commit 7a11d1c

Please sign in to comment.