Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
...t/gnomeffinway/depenizen/extensions/griefprevention/GriefPreventionLocationExtension.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,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(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...net/gnomeffinway/depenizen/extensions/griefprevention/GriefPreventionPlayerExtension.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,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(); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
src/main/java/net/gnomeffinway/depenizen/objects/griefprevention/GriefPreventionClaim.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,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!"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/gnomeffinway/depenizen/support/plugins/GriefPreventionSupport.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,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 not shown.
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