Skip to content

Commit

Permalink
PlotSquared Support for Bukkit (#161) - closes #101
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
  • Loading branch information
Mwthorn authored and Morphan1 committed Jun 19, 2017
1 parent e250923 commit a92e280
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 4 deletions.
7 changes: 7 additions & 0 deletions bukkit/pom.xml
Expand Up @@ -29,6 +29,13 @@
</repositories>

<dependencies>
<dependency>
<groupId>com.plotsquared</groupId>
<artifactId>plotsquared-api</artifactId>
<version>3.5.0u2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/PlotSquared.jar</systemPath>
</dependency>
<dependency>
<groupId>com.denizenscript</groupId>
<artifactId>depenizen-common</artifactId>
Expand Down
@@ -0,0 +1,60 @@
package com.denizenscript.depenizen.bukkit.extensions.plotsquared;


import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.intellectualcrafters.plot.api.PlotAPI;
import net.aufdemrand.denizen.objects.dLocation;
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) {
return object instanceof dLocation;
}

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

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

private PlotSquaredLocationExtension(dLocation location) {
this.location = location;
}

dLocation location;

@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <l@location.plotsquared_plot>
// @returns dPlotSquaredPlot
// @description
// Returns the plot contained by this location.
// @Plugin DepenizenBukkit, PlotSquared
// -->
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));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}
@@ -0,0 +1,82 @@
package com.denizenscript.depenizen.bukkit.extensions.plotsquared;

import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.objects.dPlotSquaredPlot;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.object.Plot;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dWorld;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.Player;

import java.util.UUID;

public class PlotSquaredPlayerExtension extends dObjectExtension {

public static boolean describes(dObject object) {
return object instanceof dPlayer;
}

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


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

private PlotSquaredPlayerExtension(dPlayer player) {
this.player = player;
}

dPlayer player;

@Override
public String getAttribute(Attribute attribute) {

// <--[tag]
// @attribute <p@player.plotsquared_plots>
// @returns dList(dPlotSquaredPlot)
// @description
// Returns all the plots a player has. Add a world to only get the plots in that specific world.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("plotsquared_plots")) {
if (attribute.hasContext(1)) {
dWorld world = dWorld.valueOf(attribute.getContext(1));
if (world == null) {
return null;
}
dList plots = new dList();
for (Plot plays : new PlotAPI().getPlayerPlots(world.getWorld(),player.getPlayerEntity())) {
plots.add(new dPlotSquaredPlot(plays).identify());
}
return plots.getAttribute(attribute.fulfill(1));
}
else {
dList plots = new dList();
for (Plot plays : new PlotAPI().getPlayerPlots(player.getPlayerEntity())) {
plots.add(new dPlotSquaredPlot(plays).identify());
}
return plots.getAttribute(attribute.fulfill(1));
}
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}
Expand Up @@ -31,7 +31,7 @@ public static dNation valueOf(String string, TagContext context) {
}

////////
// Match town name
// Match nation name

string = string.replace("nation@", "");
try {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public static dPlot valueOf(String string, TagContext context) {
}

////////
// Match town name
// Match plot name

string = string.replace("plot@", "");
try {
Expand Down Expand Up @@ -160,7 +160,7 @@ public String getAttribute(Attribute attribute) {
// Returns the plot's cuboid.
// @Plugin DepenizenBukkit, PlotMe
// -->
if (attribute.startsWith("owner")) {
if (attribute.startsWith("cuboid")) {
dWorld world = dWorld.valueOf(plot.getWorld().getName());
Location l1 = new Location(world.getWorld(), plot.getBottomX(), 0, plot.getBottomZ());
Location l2 = new Location(world.getWorld(), plot.getTopX(), 255, plot.getTopZ());
Expand Down
@@ -0,0 +1,214 @@
package com.denizenscript.depenizen.bukkit.objects;

import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.object.Plot;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dWorld;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.*;

import java.util.List;
import java.util.UUID;

public class dPlotSquaredPlot implements dObject {

/////////////////////
// OBJECT FETCHER
/////////////////

public static dPlotSquaredPlot valueOf(String string) {
return valueOf(string, null);
}

@Fetchable("plotsquaredplot")
public static dPlotSquaredPlot valueOf(String string, TagContext context) {
if (string == null) {
return null;
}

////////
// Match plotsquaredplot name

string = string.replace("plotsquaredplot@", "");
try {
List<String> split = CoreUtilities.split(string, ',');
return new dPlotSquaredPlot(new PlotAPI().getPlot(dWorld.valueOf(split.get(2)).getWorld() ,aH.getIntegerFrom(split.get(0)), aH.getIntegerFrom(split.get(1))));
}
catch (Throwable e) {
return null;
}
}

public static boolean matches(String arg) {
return arg.startsWith("plotsquaredplot@");
}

/////////////////////
// STATIC CONSTRUCTORS
/////////////////

Plot plot = null;

public dPlotSquaredPlot(Plot pl) {
plot = pl;
}

/////////////////////
// dObject Methods
/////////////////

private String prefix = "PlotSquaredPlot";

@Override
public String getPrefix() {
return prefix;
}

@Override
public dPlotSquaredPlot setPrefix(String prefix) {
this.prefix = prefix;
return this;
}

@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}

@Override
public boolean isUnique() {
return true;
}

@Override
public String getObjectType() {
return "PlotSquaredPlot";
}

@Override
public String identify() {
return "plotsquaredplot@" + plot.getId().x + "," + plot.getId().y + "," + plot.getDefaultHome().getWorld();
}

@Override
public String identifySimple() {
return identify();
}

@Override
public String getAttribute(Attribute attribute) {

// <--[tag]
// @attribute <plotsquaredplot@plot.id_x>
// @returns Element(Number)
// @description
// Returns the plot's X coordinate portion of its ID.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("x")) {
return new Element(plot.getId().x).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.id_Z>
// @returns Element(Number)
// @description
// Returns the plot's Z coordinate portion of its ID.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("z")) {
return new Element(plot.getId().y).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.home>
// @returns dLocation
// @description
// Returns the plot's current home location.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("home")) {
return new dLocation(new Location(Bukkit.getWorld(plot.getHome().getWorld()), plot.getHome().getX(),plot.getHome().getY(),plot.getHome().getZ())).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.world>
// @returns dWorld
// @description
// Returns the plot's world.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("world")) {
return dWorld.valueOf(plot.getDefaultHome().getWorld()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.owners>
// @returns dList(dPlayer)
// @description
// Returns a list of all owners of the plot.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("owners")) {
dList players = new dList();
for (UUID uuid : plot.getOwners()) {
players.add(dPlayer.valueOf(uuid.toString()).identify());
}
return players.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.trusted>
// @returns dList(dPlayer)
// @description
// Returns a list of all trusted of the plot.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("trusted")) {
dList players = new dList();
for (UUID uuid : plot.getTrusted()) {
players.add(dPlayer.valueOf(uuid.toString()).identify());
}
return players.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.members>
// @returns dList(dPlayer)
// @description
// Returns a list of all members of the plot.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("members")) {
dList players = new dList();
for (UUID uuid : plot.getMembers()) {
players.add(dPlayer.valueOf(uuid.toString()).identify());
}
return players.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <plotsquaredplot@plot.cuboid>
// @returns dCuboid
// @description
// Returns the plot's cuboid.
// @Plugin DepenizenBukkit, PlotSquared
// -->
if (attribute.startsWith("cuboid")) {
dWorld world = dWorld.valueOf(plot.getCenter().getWorld());
Location l1 = new Location(world.getWorld(), plot.getBottomAbs().getX(), 0, plot.getBottomAbs().getZ());
Location l2 = new Location(world.getWorld(), plot.getTopAbs().getX(), 255, plot.getTopAbs().getZ());
return new dCuboid(l1, l2).getAttribute(attribute.fulfill(1));
}

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

}

}

0 comments on commit a92e280

Please sign in to comment.