Skip to content

Commit

Permalink
Basic GriefPrevention Support.
Browse files Browse the repository at this point in the history
TODO: meta
  • Loading branch information
Fortifier42 committed Feb 12, 2016
1 parent 828bdab commit 79faccd
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -268,6 +268,13 @@
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/Shopkeepers.jar</systemPath>
</dependency>
<dependency>
<groupId>me.ryanhamshire</groupId>
<artifactId>GriefPrevention</artifactId>
<version>13.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/GriefPrevention.jar</systemPath>
</dependency>
</dependencies>

<build>
Expand Down
@@ -0,0 +1,83 @@
package net.gnomeffinway.depenizen.extensions.griefprevention;

import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
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;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.griefprevention.GriefPreventionClaim;

public class GriefPreventionLocationExtension extends dObjectExtension {

static DataStore dataStore = GriefPrevention.instance.dataStore;

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

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


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

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

dLocation location;

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}

if (attribute.startsWith("grief_protection")
|| attribute.startsWith("gp")
|| attribute.startsWith("griefprotection")) {
attribute = attribute.fulfill(1);

// TODO: Meta
if (attribute.startsWith("has_claim")) {
Element ignoreHeight = Element.TRUE;
if (attribute.hasContext(1)) {
ignoreHeight = new Element(attribute.getContext(1));
if (!ignoreHeight.asString().isEmpty() || !ignoreHeight.isBoolean()) {
ignoreHeight = Element.TRUE;
}
}
return new Element(dataStore.getClaimAt(location, ignoreHeight.asBoolean(), null) != null).getAttribute(attribute.fulfill(1));
}

// TODO: Meta
else if (attribute.startsWith("get_claim")) {
Claim claim = dataStore.getClaimAt(location, false, null);
if (claim == null) {
return null;
}
return new GriefPreventionClaim(claim).getAttribute(attribute.fulfill(1));
}

}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}
@@ -0,0 +1,77 @@
package net.gnomeffinway.depenizen.extensions.griefprevention;

import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.aufdemrand.denizen.objects.dPlayer;
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 net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.griefprevention.GriefPreventionClaim;

public class GriefPreventionPlayerExtension extends dObjectExtension {

static DataStore dataStore = GriefPrevention.instance.dataStore;

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

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


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

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

dPlayer player;

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}

if (attribute.startsWith("grief_protection")
|| attribute.startsWith("gp")
|| attribute.startsWith("griefprotection")) {
attribute = attribute.fulfill(1);

// TODO: Meta
if (attribute.startsWith("list_claims")) {
dList claims = new dList();
for (Claim claim : dataStore.getPlayerData(player.getOfflinePlayer().getUniqueId()).getClaims()) {
claims.add(new GriefPreventionClaim(claim).identify());
}
return claims.getAttribute(attribute.fulfill(1));
}

// TODO: Meta
else if (attribute.startsWith("claims")) {
return new Element(dataStore.getPlayerData(player.getOfflinePlayer().getUniqueId())
.getClaims().size()).getAttribute(attribute.fulfill(1));
}

}
return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}
@@ -0,0 +1,143 @@
package net.gnomeffinway.depenizen.objects.griefprevention;

import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.debugging.dB;

public class GriefPreventionClaim implements dObject, Adjustable {

static DataStore dataStore = GriefPrevention.instance.dataStore;

public static GriefPreventionClaim valueOf(String id) {
return valueOf(id, null);
}

@Fetchable("gpclaim")
public static GriefPreventionClaim valueOf(String id, TagContext context) {
long claimID;
try {
claimID = Long.valueOf(id);
}
catch (NumberFormatException e) {
return null;
}
Claim claim = dataStore.getClaim(claimID);
if (claim == null) {
return null;
}
return new GriefPreventionClaim(claim);
}

public GriefPreventionClaim(Claim claim) {
this.claim = claim;
}

private String prefix;
Claim claim;

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

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

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

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

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

@Override
public String identify() {
return "gpclaim@" + claim.getID();
}

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

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}

// TODO: Meta
if (attribute.startsWith("id")) {
return new Element(claim.getID()).getAttribute(attribute.fulfill(1));
}

// TODO: Meta
else if (attribute.startsWith("owner")) {
return new dPlayer(dPlayer.getAllPlayers().get(CoreUtilities.toLowerCase(claim.getOwnerName())))
.getAttribute(attribute.fulfill(1));
}

// TODO: Meta
else if (attribute.startsWith("cuboid")) {
dCuboid cuboid = new dCuboid();
cuboid.addPair(new dLocation(claim.getLesserBoundaryCorner()), new dLocation(claim.getGreaterBoundaryCorner()));
return cuboid.getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();

// TODO: Meta
if (mechanism.matches("owner") && mechanism.requireObject(dPlayer.class)) {
dPlayer player = value.asType(dPlayer.class);
try {
dataStore.changeClaimOwner(claim, player.getOfflinePlayer().getUniqueId());
}
catch (Exception e) {
dB.echoError("Unable to transfer ownership of claim: " + this.identify() + " to " + player.identify());
}
}

// Iterate through this object's properties' mechanisms
for (Property property : PropertyParser.getProperties(this)) {
property.adjust(mechanism);
if (mechanism.fulfilled()) {
break;
}
}

if (!mechanism.fulfilled()) {
mechanism.reportInvalid();
}
}

@Override
public void applyProperty(Mechanism mechanism) {
dB.echoError("Cannot apply Properties to a GriefPreventionClaim!");
}
}
@@ -0,0 +1,18 @@
package net.gnomeffinway.depenizen.support.plugins;

import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.gnomeffinway.depenizen.extensions.griefprevention.GriefPreventionLocationExtension;
import net.gnomeffinway.depenizen.extensions.griefprevention.GriefPreventionPlayerExtension;
import net.gnomeffinway.depenizen.objects.griefprevention.GriefPreventionClaim;
import net.gnomeffinway.depenizen.support.Support;

public class GriefPreventionSupport extends Support {

public GriefPreventionSupport() {
registerObjects(GriefPreventionClaim.class);
registerProperty(GriefPreventionPlayerExtension.class, dPlayer.class);
registerProperty(GriefPreventionLocationExtension.class, dLocation.class);
}

}
Binary file added src/main/resources/GriefPrevention.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Expand Up @@ -3,7 +3,7 @@ authors: [GnomeffinWay, Morphan1]
version: ${project.version} (build ${BUILD_NUMBER})
main: net.gnomeffinway.depenizen.Depenizen
depend: [Denizen]
softdepend: [mcMMO, BattleNight, Towny, Factions, Votifier, Jobs, Heroes, pvparena, Dynmap, WorldEdit, WorldGuard, Essentials, pvpstats, HyperConomy, SkillAPI, Prism, TerrainControl, PlotMe, SimpleClans, MobArena, ASkyBlock, NoCheatPlus, MythicMobs, ShopKeepers]
softdepend: [mcMMO, BattleNight, Towny, Factions, Votifier, Jobs, Heroes, pvparena, Dynmap, WorldEdit, WorldGuard, Essentials, pvpstats, HyperConomy, SkillAPI, Prism, TerrainControl, PlotMe, SimpleClans, MobArena, ASkyBlock, NoCheatPlus, MythicMobs, ShopKeepers, GriefPrevention]

commands:
depenizen:
Expand Down

0 comments on commit 79faccd

Please sign in to comment.