Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PlotSquared Events and minor changes (#168)
* 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
Showing
7 changed files
with
353 additions
and
19 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
...va/com/denizenscript/depenizen/bukkit/events/plotsquared/PlayerEntersPlotScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ava/com/denizenscript/depenizen/bukkit/events/plotsquared/PlayerLeavePlotScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...om/denizenscript/depenizen/bukkit/extensions/plotsquared/PlotSquaredElementExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.