Skip to content

Commit

Permalink
PlotSquared Events and minor changes (#168)
Browse files Browse the repository at this point in the history
* Start of PlotSquared Support

Not Finished yet!! But its the start of plotsquared add-ons.

* More plotsquared stuff

still not finished yet

* Finishing Support of PlotSquared

Everything should work now! Yay!

* Remove old repo

This should have been the normal way, but plotsquared has not yet
included their api

* Comment Cleanup and few changes

* Started extension of PlotSquared Support

additional events and tags, currently not stable

* Fix meta

* fix redundant and remove debug

* changed getWorld methods
  • Loading branch information
Mwthorn authored and Morphan1 committed Sep 26, 2017
1 parent 17c5b78 commit 45ea469
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 19 deletions.
@@ -0,0 +1,116 @@
package com.denizenscript.depenizen.bukkit.events.plotsquared;

import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dPlayer;
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 player enters plotsquaredplot
// plotsquared player enters <dplotsquaredplot>
//
// @Regex ^on plotsquared player [^\s]+ level changes( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Cancellable false
//
// @Triggers when a player enters a plot.
//
// @Context
// <context.plot> returns the plot the player entered.
//
// @Plugin DepenizenBukkit, PlotSquared
//
// -->

public class PlayerEntersPlotScriptEvent extends BukkitScriptEvent implements Listener {

public PlayerEntersPlotScriptEvent() {
instance = this;
}

public static PlayerEntersPlotScriptEvent instance;
public PlayerEnterPlotEvent event;
public dPlayer player;
public dPlotSquaredPlot plot;

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

@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 "PlayerEnterPlotEvent";
}

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

@Override
public void destroy() {
PlayerEnterPlotEvent.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(player, null);
}

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

@EventHandler
public void onPlotEnter(PlayerEnterPlotEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
player = dPlayer.mirrorBukkitPlayer(event.getPlayer());
plot = new dPlotSquaredPlot(event.getPlot());
this.event = event;
fire();
}
}
@@ -0,0 +1,115 @@
package com.denizenscript.depenizen.bukkit.events.plotsquared;

import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dPlayer;
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 player leaves plotsquaredplot
// plotsquared player exits plotsquaredplot
// plotsquared player leaves <dplotsquaredplot>
// plotsquared player exits <dplotsquaredplot>
//
// @Regex ^on plotsquared player [^\s]+ level changes( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Cancellable false
//
// @Triggers when a player leaves a plot.
//
// @Context
// <context.plot> returns the plot the player left.
//
// @Plugin DepenizenBukkit, PlotSquared
//
// -->

public class PlayerLeavePlotScriptEvent extends BukkitScriptEvent implements Listener {

public PlayerLeavePlotScriptEvent() {
instance = this;
}

public static PlayerLeavePlotScriptEvent instance;
public PlayerLeavePlotEvent event;
public dPlayer player;
public dPlotSquaredPlot plot;

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

@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 "PlayerLeavePlotEvent";
}

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

@Override
public void destroy() {
PlayerLeavePlotEvent.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(player, null);
}

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

@EventHandler
public void onPlotLeave(PlayerLeavePlotEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
player = dPlayer.mirrorBukkitPlayer(event.getPlayer());
plot = new dPlotSquaredPlot(event.getPlot());
this.event = event;
fire();
}
}
@@ -0,0 +1,63 @@
package com.denizenscript.depenizen.bukkit.extensions.plotsquared;

import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;

public class PlotSquaredElementExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return object instanceof Element;
}

public static PlotSquaredElementExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new PlotSquaredElementExtension((Element) object);
}
}

///////////////////
// Instance Fields and Methods
/////////////

private PlotSquaredElementExtension(Element element) {
this.element = element;
}

Element element;

@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <el@element.as_plotsquared_plot>
// @returns dPlotSquaredPlot
// @description
// Returns the element as a dPlotSquaredPlot.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("as_plotsquared_plot")) {
try {
dB.log(element.toString());
return dPlotSquaredPlot.valueOf(element.toString()).getAttribute(attribute.fulfill(1));
}
catch (Exception e) {
if (!attribute.hasAlternative()) {
dB.echoError(e);
}
}
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}
Expand Up @@ -5,12 +5,12 @@
import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.intellectualcrafters.plot.api.PlotAPI;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;


public class PlotSquaredLocationExtension extends dObjectExtension {

public static boolean describes(dObject object) {
Expand Down Expand Up @@ -47,7 +47,14 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("plotsquared_plot")) {
org.bukkit.Location loca = new org.bukkit.Location(location.getWorld(),location.getBlockX(),location.getBlockY(),location.getBlockZ(),location.getYaw(),location.getPitch());
return new dPlotSquaredPlot(new PlotAPI().getPlot(loca)).getAttribute(attribute.fulfill(1));
try {
return new dPlotSquaredPlot(new PlotAPI().getPlot(loca)).getAttribute(attribute.fulfill(1));
}
catch (Exception e) {
if (!attribute.hasAlternative()) {
dB.echoError(e);
}
}
}

return null;
Expand Down
Expand Up @@ -45,10 +45,10 @@ private PlotSquaredPlayerExtension(dPlayer player) {
public String getAttribute(Attribute attribute) {

// <--[tag]
// @attribute <p@player.plotsquared_plots>
// @attribute <p@player.plotsquared_plots[<w@world>]>
// @returns dList(dPlotSquaredPlot)
// @description
// Returns all the plots a player has. Add a world to only get the plots in that specific world.
// Returns a list of plots a player has in a world. Exclude the context to get plots in all worlds.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("plotsquared_plots")) {
Expand Down

0 comments on commit 45ea469

Please sign in to comment.